-
Notifications
You must be signed in to change notification settings - Fork 1
/
QuickLogger.h
141 lines (138 loc) · 5.46 KB
/
QuickLogger.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* File: QUICKLogger.h
* Author: hitman
*
* Created on January 7, 2013, 11:31 AM
*/
#ifndef QUICKLOGGER_H
#define QUICKLOGGER_H
#include <string>
#include <memory>
using namespace std;
/*
To Do:
implement log levels
*
*/
class QuickLogger {
public:
/**
* Constructor. Any ofstream exceptions are written to stderr.
* @param path - Required, path to the file. Could be absolute or relative.
* @param name - File name. Note that the complete file name will be in
* format QL_<name>_<time_format>.log.csv
* @param time_format - Time format. Default is YMDHm. Accepted placeholders are:
* <Y> - 4 digit year
* <M> - 2 digit month
* <D> - 2 digit day of the month
* <h> - 2 digit hour
* <m> - 2 digit minute
* <s> - 2 digit second
* <l> - 6 digit microsecond
*
* @param rolloverperiod - Definition how often to rollover files.
* Several format options are available as below
* -> Time-frame definitions. Available definitions are:
* <second>, <minute>, <hour>, <day>, <week>, <month>, <year>
* A multiplier could be supplied to the time-frames state above,
* the format is <multiplier> <time-frame>[<@hh:mm:ss>]
* Here, multiplier can be any positive integer, time-frame could be
* any of the time-frame definitions above. Also, additional hour,
* minute and second could be supplied to customize the rollover event.
* NOTE: hour, minute and second are only available to specify with the
* following time-frames: <day>,<week>,<month>,<year>, otherwise it
* will simply be ignored. If time parameter is not given with the
* time-frames which accept it, default rollover time will be 00:00:00.
* Examples: '200 seconds', '30 minutes', '1 hour', '1 day@15:00',
* '2 weeks@12:00:00'
* -> Week days. Format is <weekday>[<@hh:mm:ss>]. Available weekdays are
* <Monday>,<Tuesday>,<Wednesday>,<Thursday>,<Friday>, <Saturday>,
* <Sunday>. It is also possible to precise the rollover event with
* optional time argument. Default value is 00:00:00
* Examples: 'Sunday@03:00:00', 'Monday', 'Friday@09'.
*
* If nothing is supplied or argument could not be parsed, rollover will
* occur every 86400 seconds, from the start of the application.
*/
QuickLogger(string path,
string name,
string time_format,
string rolloverperiod = "");
/**
* QuickLogger object is not copyable, thus copy constructor is disabled.
*/
QuickLogger(const QuickLogger& orig) =delete;
/**
Destructor
*/
~QuickLogger();
/**
* Write message to the log file. Any exceptions are written to stderr.
* Average latency of this call is around 10 microseconds on an average
* end-user PC or laptop.
* @param message
* @param loglevel - a custom or standard level(if custom is not defined).
* Default log levels are: FATAL,ERROR,WARNING,INFO,DEBUG. Log levels are
* case sensitive.
* @param component - Component name, could be omitted.
*/
void Log(string message, string loglevel, string component = "");
/**
* Use this function to set the desirable order of fields-per-line.
*
* @param fields - a list of fields separated by comma.
* Available fields are (case sensitive): TIME,LEVEL,COMPONENT,MESSAGE.
* At least 1 field should be set, otherwise, default fields will be used.
*/
void Setfields(string fields);
/**
* Set log levels, all string values available. Use the same values when
* logging any messages.
* @param levels - a list of log levels separated by comma.
* Default fields are: FATAL,ERROR,WARNING,INFO,DEBUG
*/
void Setloglevels(string levels);
/**
* Get the counter of buffer overflows for the current file. This counter
* is reset for each file and printed on the last line of the file.
* @return long - counter of buffer overflows.
*/
long Getbufferoverflows();
/**
* Returns the currently opened absolute file name
* @return string - filename
*/
string Getfilename();
/**
* Toggle log level
* @param level - string representation of the log level
* @param enabled - trivial - true or false
*/
void Toggleloglevel(string level, bool enabled);
/* With the configuration below it's possible to tune the performance of
* the QuickLogger. With default configuration QuickLogger is able to handle
* 35 000 MPS (messages per second) without buffer overflows on an average
* end-user PC or laptop. */
/**
* Sets the flush frequency at which buffer is flushed to disk.
* Default is 10 milliseconds
* @param flushfreq - time, in milliseconds
*/
void Setflushfrequency(unsigned int flushfreq);
/**
* Sets the buffer size. Small buffer will probably cause more buffer
* overflows
* Default is 1000 messages.
* @param buffersize - buffer size in messages
*/
void Setbuffersize(unsigned int buffersize);
private:
/**
* Private implementation of the library. This approach allows updates of
* the library (if interface does not change) without the recompilation of
* user application.
*/
class impl;
std::unique_ptr<impl> PrivateImpl;
};
#endif /* QUICKLOGGER_H */