-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLog.h
More file actions
77 lines (68 loc) · 2.28 KB
/
Log.h
File metadata and controls
77 lines (68 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef LOG_H
#define LOG_H
#include "cppCORE_global.h"
#include <QString>
#include <QElapsedTimer>
#include <QThreadPool>
#include <QMutex>
/**
@brief Singleton logging handler for command line applications.
@note The DEBUG level is missing by purpose: Debugging output should be done with QDebug (it can be disabled for
*/
class CPPCORESHARED_EXPORT Log
{
public:
enum LogLevel
{
LOG_PERFORMANCE = 1,
LOG_INFO = 2,
LOG_WARNING = 4,
LOG_ERROR = 8
};
///Logs message using ERROR level.
static void error(const QString& message);
///Logs message using WARNING level.
static void warn(const QString& message);
///Logs message using INFO level.
static void info(const QString& message);
///Logs message using PERF level (performance data).
static void perf(const QString& message);
///Convenice: Logs a performance message appending the human-readable elapsed time.
static void perf(const QString& message, QElapsedTimer elapsed);
///Convenice: Logs basic application info (path, version, ...) using INFO level.
static void appInfo();
/// Activates/deactivates the command line logging. Default is enabled.
static void setCMDEnabled(bool enabled);
/// Activates/deactivates file logging. Default is disabled.
static void setFileEnabled(bool enabled);
///Sets the log file. Default is application name plus '.log' extention.
static void setFileName(QString filename);
///Returns the used log file.
static QString fileName();
///Enables/disables log levels (bit-wise OR of levels). Default is all levels enabled.
static void enableLogLevels(int level);
protected:
///Default constructor not public
Log();
///Copy constructor "declared away"
Log(const Log&) = delete;
///Returns the logger singleton instance.
static Log& inst();
///Internal message handler that does the actual logging.
void logMessage(LogLevel level, const QString& message);
///Returns the log level string.
QString levelString(LogLevel level);
///Command line logging
bool log_cmd_;
///File logging
bool log_file_;
///Log file name
QString log_file_name_;
///Status of log levels
int enabled_;
///Thread pool to control writting logs into a file
QThreadPool thread_pool_;
///Mutex for the situation when the server starts a new log file
mutable QMutex log_file_name_mutex_;
};
#endif // LOG_H