-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogContext.hpp
67 lines (48 loc) · 1.83 KB
/
LogContext.hpp
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
/******************************************************************************
* LogContext.hpp
*
* Context of the current log, i.e. set of logs that may be shown if the
* current log's level is above a specific threshold.
*
* Copyright (C) 2012-2016 Pietro Mele
* Released under a GPL 3 license.
*
*
*****************************************************************************/
#ifndef LOGCONTEXT_HPP
#define LOGCONTEXT_HPP
#include <queue>
#include <string>
namespace log_viewer {
class LogContext
{
public:
LogContext() :
width(0), minLevelForContext(5 /*ERROR*/), minContextLevel(10 /*context disabled*/) {}
int StorePastLog(const std::string &_log, int _level, int _minLevel, int _logNumberPre);
int ExtractPastLog(std::string &_log); // return log id/number
int Width() const { return width; }
int MinLevelForContext() const { return minLevelForContext; }
int MinContextLevel() const { return minContextLevel; }
int NPastLogs() const { return pastLogs.size(); }
int Width(int _w) { return (width = (_w >= 0)?_w:width); }
int MinLevelForContext(int _ml) { return (minLevelForContext = (_ml >= 0)?_ml:minLevelForContext); }
int MinContextLevel(int _ml) { return (minContextLevel = (_ml >= 0)?_ml:minContextLevel); }
void Erase();
void Dump() const;
private:
int width; // number of logs before and after the current one
int minLevelForContext; // the minimum level a log must have to get a context
int minContextLevel; // the minimum level a log must have to be part of the context
struct PastLog {
std::string log;
int logNumber;
PastLog() : logNumber(0) {}
PastLog(const std::string &_log, int _logNum = 0)
: log(_log), logNumber(_logNum) {}
};
std::queue<PastLog> pastLogs;
};
} // log_viewer
#endif // LOGCONTEXT_HPP