-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappender.h
More file actions
69 lines (58 loc) · 1.94 KB
/
appender.h
File metadata and controls
69 lines (58 loc) · 1.94 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
#ifndef _APPENDER_H_
#define _APPENDER_H_
#include "message.h"
#include "gen_utils.h"
#include <cstdio>
#include <cstdarg>
#include <vector>
/*
* Author: Alexander Issayev
*/
/* Appender class, provides RAII semantics for writing
* to log files. The static append method writes to all
* open appenders.
*/
namespace simple_log {
class Appender {
public:
/**
* Opens file in write or append mode.
* Throws an exception if file cannot be opened.
*
* @param filename: File to be written to.
* @param maxlvl: Highest level of debugging info to append.
* @param append: Append to file or overwrite
*/
Appender(const char * filename, Level::LoggingLevel maxlvl, bool append);
/* Enable writing to cerr with Max Level: maxLvl*/
static void enableConsole(Level::LoggingLevel maxLvl);
/* Stop writing to console */
static void disableConsole();
/* Destroy me and release file handle. */
~Appender();
/**
* Append given message to all active appenders
* and console if applicable.
*
* @param msg: Message to append.
* @param lvl: Level of message to append.
*/
static void appendAll(Level::LoggingLevel lvl, Message * msg);
private:
/* Do not allow copy constructors or assignments */
DISALLOW_COPY_AND_ASSIGN(Appender);
/* Write message to my file */
void append(Level::LoggingLevel lvl, Message * msg);
int index;
Level::LoggingLevel maxlvl;
FILE * logfile;
const char * filename;
/* Information about console */
static Level::LoggingLevel consoleLevel;
static bool writeToConsole;
/* List of all appenders to write to
List does not own appenders */
static std::vector<Appender *> appenders;
};
}
#endif