ddc
ddcLog.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 //
3 // DDC originally by Alexey Sokirko
4 // Changes and modifications 2011-2018 by Bryan Jurish
5 //
6 // This file is part of DDC (formerly in string_socket.h)
7 //
8 // DDC is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // DDC is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with DDC. If not, see <http://www.gnu.org/licenses/>.
20 //
21 #ifndef DDC_LOG_H
22 #define DDC_LOG_H
23 
24 #include <string>
25 
26 //======================================================================
27 // Types & Constants
28 
29 /*-- old, ununtuitively-named log-levels
30  enum ProtocolDensityEnum {
31  pdWeakDensity = 0,
32  pdMediumDensity = 1,
33  pdHeavyDensity = 2
34  };
35  --*/
36 
38 typedef int DDCLogLevel;
39 
40 extern const DDCLogLevel ddcLLUnknown; //< log-level: undefined (=-1)
41 extern const DDCLogLevel ddcLLSilent; //< log-level: no logging (=0)
42 extern const DDCLogLevel ddcLLError; //< log-level: errors only (=1)
43 extern const DDCLogLevel ddcLLWarn; //< log-level: errors+warnings (=2)
44 extern const DDCLogLevel ddcLLInfo; //< log-level: info messages (=3 ~ pdWeakDensity)
45 extern const DDCLogLevel ddcLLDebug; //< log-level: debug messages (=4 ~ pdMediumDensity)
46 extern const DDCLogLevel ddcLLTrace; //< log-level: trace messages (=5 ~ pdHeavyDensity)
47 
50 
52 extern const DDCLogLevel pdWeakDensity; //< log-level pre-v2.1 compatibility alias: ddcLLInfo
53 extern const DDCLogLevel pdMediumDensity; //< log-level pre-v2.1 compatibility alias: ddcLLDebug
54 extern const DDCLogLevel pdHeavyDensity; //< log-level pre-v2.1 compatibility alias: ddcLLTrace
55 
56 //======================================================================
57 // Globals
58 
60 extern bool ddcLogToFiles;
61 
63 extern bool ddcLogToStderr;
64 
66 extern bool ddcLogToSyslog;
67 
70 
72 #define concord_daemon_log_files ddcLogToFiles
73 
75 #define concord_daemon_log_stderr ddcLogToStderr
76 
78 #define concord_daemon_log_syslog ddcLogToSyslog
79 
80 //======================================================================
81 // Functions
82 
84 DDCLogLevel GetLogLevel(const std::string& Name);
85 
87 extern const char* LogLevelName(DDCLogLevel Level);
88 
90 extern DDCLogLevel SetLogLevel(DDCLogLevel Level);
91 
93 extern void ddcLog(const std::string& msg);
94 
96 inline void concord_daemon_log(const std::string& t)
97 { ddcLog(t); }
98 
100 #define ddcLogIf(Test,Msg) if (Test) ddcLog(Msg)
101 
103 #define ddcLogError(Msg) ddcLogIf((ddcLogLevel >= ddcLLError),Msg)
104 
106 #define ddcLogWarn(Msg) ddcLogIf((ddcLogLevel >= ddcLLWarn),Msg)
107 
109 #define ddcLogInfo(Msg) ddcLogIf((ddcLogLevel >= ddcLLInfo),Msg)
110 
112 #define ddcLogDebug(Msg) ddcLogIf((ddcLogLevel >= ddcLLDebug),Msg)
113 
115 #define ddcLogTrace(Msg) ddcLogIf((ddcLogLevel >= ddcLLTrace),Msg)
116 
118 #define ddcLogDie(Msg) { ddcLogError(Msg); abort(); }
119 
120 
121 #endif /* DDC_LOG_H */
122 
123 /*--- emacs style variables ---
124  * Local Variables:
125  * mode: C++
126  * c-file-style: "ellemtel"
127  * c-basic-offset: 4
128  * tab-width: 8
129  * indent-tabs-mode: nil
130  * End:
131  */
const DDCLogLevel ddcLLTrace
Definition: ddcLog.cpp:44
DDCLogLevel ddcLogLevel
global log-level
Definition: ddcLog.cpp:57
DDCLogLevel GetLogLevel(const std::string &Name)
Definition: ddcLog.cpp:65
bool ddcLogToSyslog
bool: whether to output log messages via syslog (default=false)
Definition: ddcLog.cpp:55
void concord_daemon_log(const std::string &t)
pre-v2.1 compatible alias for ddcLog()
Definition: ddcLog.h:96
int DDCLogLevel
Definition: ddcLog.h:38
void ddcLog(const std::string &msg)
write a single log-message, implicitly appending a newline
const DDCLogLevel pdHeavyDensity
Definition: ddcLog.cpp:48
DDCLogLevel ProtocolDensityEnum
Definition: ddcLog.h:49
bool ddcLogToStderr
bool: whether to output log messages on stderr (default=false)
Definition: ddcLog.cpp:54
const DDCLogLevel ddcLLWarn
Definition: ddcLog.cpp:41
const DDCLogLevel pdWeakDensity
Definition: ddcLog.cpp:46
const DDCLogLevel ddcLLInfo
Definition: ddcLog.cpp:42
const DDCLogLevel ddcLLDebug
Definition: ddcLog.cpp:43
const char * LogLevelName(DDCLogLevel Level)
Definition: ddcLog.cpp:101
bool ddcLogToFiles
bool: whether to output log messages to local log-files REGISTRY("Software\\Dialing\\Logs\\Main")/log...
Definition: ddcLog.cpp:53
Definition: morph_const.h:107
const DDCLogLevel ddcLLError
Definition: ddcLog.cpp:40
DDCLogLevel SetLogLevel(DDCLogLevel Level)
Definition: ddcLog.cpp:109
const DDCLogLevel ddcLLUnknown
Definition: ddcLog.cpp:38
const DDCLogLevel ddcLLSilent
Definition: ddcLog.cpp:39
const DDCLogLevel pdMediumDensity
Definition: ddcLog.cpp:47