aboutsummaryrefslogtreecommitdiff
path: root/src/old/multilog.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/old/multilog.h')
-rw-r--r--src/old/multilog.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/old/multilog.h b/src/old/multilog.h
new file mode 100644
index 0000000..692095a
--- /dev/null
+++ b/src/old/multilog.h
@@ -0,0 +1,130 @@
1#ifndef MULTILOG_H
2#define MULTILOG_H
3
4#include <stdio.h>
5#include <stdarg.h>
6#include <time.h>
7
8#include "ringlist.h"
9#include "linkedlist.h"
10#include "singleton.h"
11
12/**
13 * Calls the DetailLog function but includes pre-processor macros to fill in
14 * most of the fields for you. This makes your life a lot easier, and makes the
15 * log useful for system debugging as well as just letting people know what's
16 * going on.
17 *@param LEVEL The log level, comes from an enum in the MultiLog class.
18 *@param FORMAT The text to store in the log, using printf style formatting.
19 *@param ... Parameters to help format the text in the FROMAT param.
20 */
21#define LineLog( LEVEL, FORMAT, ...) DetailLog( LEVEL, __FILE__, __LINE__, __PRETTY_FUNCTION__, FORMAT, ##__VA_ARGS__ )
22
23#define MultiLineLog( LEVEL, FORMAT, ...) MultiLog::getInstance().DetailLog( LEVEL, __FILE__, __LINE__, __PRETTY_FUNCTION__, FORMAT, ##__VA_ARGS__ )
24
25/** MultiLog keeps track of logfile info in a myriad of varieties, and is
26 * easily configurable between them all. It allows output to the standard
27 * output, error output, files, networks, and streams, which includes memory
28 * buffers.
29 * MultiLog uses the singleton pattern to keep only a single instance of
30 * the log. Instead of instantiating a new copy, call the getLog method.
31 *@author Mike Buland
32 */
33class MultiLog : public Singleton<MultiLog>
34{
35 friend class Singleton<MultiLog>;
36public:
37 /**
38 * Keeps track of a single log entry, in a standard format, that can be
39 * processed by any MultiLogChannel derrived class.
40 *@author Mike Buland
41 */
42 typedef struct LogEntry
43 {
44 /** Safely delete a log entry. */
45 virtual ~LogEntry();
46 time_t xTime; /**< The time the log entry was made. */
47 int nLevel; /**< The log-level of the entry. */
48 char *lpFile; /**< The name of the file this entry came from. */
49 int nLine; /**< The line number that this log came from. */
50 char *lpText; /**< The text content of this log entry. */
51 } LogEntry;
52
53protected:
54 /**
55 * Private constructor, this ensures that this is a singleton.
56 */
57 MultiLog();
58
59 /**
60 * Destroy the multilog.
61 */
62 virtual ~MultiLog();
63
64 /**
65 * Append a new logentry to the log list, possibly pushing an old entry off.
66 *@param pEntry The new entry to append.
67 */
68 void append( LogEntry *pEntry );
69
70 /**
71 * The actual log entry storage mechanism.
72 */
73 RingList *rEntry;
74
75 /**
76 * The number of entries that have rolled off the end of the RingList.
77 */
78 unsigned long nEntriesLost;
79
80 /**
81 * A list of all channels that are registered with the MultiLog.
82 */
83 LinkedList *lChannel;
84
85public:
86
87 /** Sends info to the logfile.
88 *@param nLevel The type of data being logged (error, info, etc.)
89 *@param lpFormat The data to send to the log.
90 *@author Mike Buland
91 */
92 //void Log( int nLevel, const char *lpFormat, ...);
93
94 /** Sends info to the logfile with extra information, including the files
95 * that it was called from and the line in the code. Besides that, it's
96 * exactly the same as Log. Please use the LineLog macro to make DetailLog
97 * really easy to use. It operates exacly like Log, but inserts the
98 * builtin macros as the lpFile and nLine parameters.
99 *@param nLevel The type of data being logged (error, info, etc.)
100 *@param lpFile The name of the file that called the log function.
101 *@param nLine The line in the file that this log function was called from.
102 *@param lpFunction The name of the function that called the log function.
103 *@param lpFormat The data to send to the log.
104 *@author Mike Buland
105 */
106 void DetailLog( int nLevel, const char *lpFile, int nLine, const char *lpFunction, const char *lpFormat, ...);
107
108 /**
109 * Adds a logging channel to the MultiLog channel chain. Every added
110 * channel will automatically receive a complete log of everything that
111 * happened before the channel was added as well as all future messages.
112 *@param pChannel A pointer to the pre-contructed channel object to add.
113 */
114 void addChannel( class MultiLogChannel *pChannel );
115
116 /** The various pre-defined levels available to use when logging.
117 * The person logging can make up their own, just make sure to remember
118 * which value is which (all levels are integers).
119 *@author Mike Buland
120 */
121 enum Levels
122 {
123 LError,
124 LWarning,
125 LInfo,
126 LStatus
127 };
128};
129
130#endif