From ebf1e2c5211f98347b11108208bc6368c071bdd7 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 26 May 2016 23:23:45 -0400 Subject: [PATCH] log: Added debug function --- src/CMakeLists.txt | 1 + src/log.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/timew.h | 6 ++++++ 3 files changed, 54 insertions(+) create mode 100644 src/log.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1130c510..5bd2bee6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,7 @@ set (timew_SRCS CLI.cpp CLI.h data.cpp init.cpp helper.cpp + log.cpp util.cpp) set (libshared_SRCS libshared/src/Args.cpp libshared/src/Args.h diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 00000000..9e924b10 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +static bool debugMode = false; + +//////////////////////////////////////////////////////////////////////////////// +void enableDebugMode (bool value) +{ + debugMode = value; +} + +//////////////////////////////////////////////////////////////////////////////// +void debug (const std::string& msg) +{ + if (debugMode) + std::cout << Color ("gray4").colorize (msg) << "\n"; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/timew.h b/src/timew.h index fd9e8da1..61179447 100644 --- a/src/timew.h +++ b/src/timew.h @@ -72,6 +72,12 @@ std::map createTagColorMap (const Rules&, Palette&, const s int quantizeTo15Minutes (const int); bool dayIsHoliday (const Rules&, const Datetime&); +// log.cpp +void enableDebugMode (bool); +void enableQuietMode (bool); +void debug (const std::string&); +void error (const std::string&); + // utiƀ.cpp std::string osName (); std::string escape (const std::string&, int);