Torc  0.1
torclogging.h
Go to the documentation of this file.
1 #ifndef TORCLOGGING_H_
2 #define TORCLOGGING_H_
3 
4 #ifdef __cplusplus
5 #include <QString>
6 #endif
7 #include <stdint.h>
8 #include <errno.h>
9 
10 #include "torcloggingdefs.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #define VERBOSE_LEVEL_NONE (gVerboseMask == 0)
17 #define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_) \
18  (((gVerboseMask & (_MASK_)) == (_MASK_)) && gLogLevel >= (_LEVEL_))
19 
20 #define LOG(_MASK_, _LEVEL_, _STRING_) \
21  do { \
22  if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
23  { \
24  PrintLogLine(_MASK_, (LogLevel)_LEVEL_, \
25  __FILE__, __LINE__, __FUNCTION__, \
26  _STRING_.toLocal8Bit().constData()); \
27  } \
28  } while (false)
29 
30 void PrintLogLine(uint64_t mask, LogLevel level, const char *file, int line,
31  const char *function, const char *format, ...);
32 
33 extern LogLevel gLogLevel;
34 extern uint64_t gVerboseMask;
35 }
36 
37 extern QString gLogPropagationArgs;
38 extern QString gVerboseString;
39 
40 void StartLogging(const QString &Logfile, int progress = 0,
41  int quiet = 0, const QString &level = QStringLiteral("info"),
42  bool Propagate = false);
43 void StopLogging(void);
44 void CalculateLogPropagation(void);
45 bool GetQuietLogPropagation(void);
46 LogLevel GetLogLevel(const QString &level);
47 QString GetLogLevelName(LogLevel level);
48 int ParseVerboseArgument(const QString &arg);
49 QString LogErrorToString(int errnum);
50 
56 #define ENO (QString("\n\t\t\teno: ") + LogErrorToString(errno))
57 #define ENO_STR ENO.toLocal8Bit().constData()
58 
59 #endif
60 
61 // vim:ts=4:sw=4:ai:et:si:sts=4
LogLevel gLogLevel
QString gLogPropagationArgs
int ParseVerboseArgument(const QString &arg)
void StopLogging(void)
QString LogErrorToString(int errnum)
bool GetQuietLogPropagation(void)
void PrintLogLine(uint64_t mask, LogLevel level, const char *file, int line, const char *function, const char *format,...)
LogLevel GetLogLevel(const QString &level)
QString gVerboseString
uint64_t gVerboseMask
QString GetLogLevelName(LogLevel level)
void StartLogging(const QString &Logfile, int progress=0, int quiet=0, const QString &level=QStringLiteral("info"), bool Propagate=false)
void CalculateLogPropagation(void)