aboutsummaryrefslogtreecommitdiff
path: root/src/multilog.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
committerMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
commitf7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch)
tree53cec4864776e07950e3c72f2a990a1017d08045 /src/multilog.h
downloadlibbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to 'src/multilog.h')
-rw-r--r--src/multilog.h145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/multilog.h b/src/multilog.h
new file mode 100644
index 0000000..30ad8d7
--- /dev/null
+++ b/src/multilog.h
@@ -0,0 +1,145 @@
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
11/**
12 * Calls the DetailLog function but includes pre-processor macros to fill in
13 * most of the fields for you. This makes your life a lot easier, and makes the
14 * log useful for system debugging as well as just letting people know what's
15 * going on.
16 *@param LEVEL The log level, comes from an enum in the MultiLog class.
17 *@param FORMAT The text to store in the log, using printf style formatting.
18 *@param ... Parameters to help format the text in the FROMAT param.
19 */
20#define LineLog( LEVEL, FORMAT, ...) DetailLog( LEVEL, __FILE__, __LINE__, __PRETTY_FUNCTION__, FORMAT, ##__VA_ARGS__ )
21
22/** MultiLog keeps track of logfile info in a myriad of varieties, and is
23 * easily configurable between them all. It allows output to the standard
24 * output, error output, files, networks, and streams, which includes memory
25 * buffers.
26 * MultiLog uses the singleton pattern to keep only a single instance of
27 * the log. Instead of instantiating a new copy, call the getLog method.
28 *@author Mike Buland
29 */
30class MultiLog
31{
32public:
33 /**
34 * Keeps track of a single log entry, in a standard format, that can be
35 * processed by any MultiLogChannel derrived class.
36 *@author Mike Buland
37 */
38 typedef struct LogEntry
39 {
40 /** Safely delete a log entry. */
41 ~LogEntry();
42 time_t xTime; /**< The time the log entry was made. */
43 int nLevel; /**< The log-level of the entry. */
44 char *lpFile; /**< The name of the file this entry came from. */
45 int nLine; /**< The line number that this log came from. */
46 char *lpText; /**< The text content of this log entry. */
47 } LogEntry;
48
49private:
50 /**
51 * Private constructor, this ensures that this is a singleton.
52 */
53 MultiLog();
54
55 /**
56 * The only instance of MultiLog ever.
57 */
58 static MultiLog *singleLog;
59
60 /**
61 * Append a new logentry to the log list, possibly pushing an old entry off.
62 *@param pEntry The new entry to append.
63 */
64 void append( LogEntry *pEntry );
65
66 /**
67 * The actual log entry storage mechanism.
68 */
69 RingList *rEntry;
70
71 /**
72 * The number of entries that have rolled off the end of the RingList.
73 */
74 unsigned long nEntriesLost;
75
76 /**
77 * A list of all channels that are registered with the MultiLog.
78 */
79 LinkedList *lChannel;
80
81public:
82 /**
83 * Destroy the multilog.
84 *@todo Why is this public? Does it need to be?
85 */
86 ~MultiLog();
87
88 /** Sends info to the logfile.
89 *@param nLevel The type of data being logged (error, info, etc.)
90 *@param lpFormat The data to send to the log.
91 *@author Mike Buland
92 */
93 //void Log( int nLevel, const char *lpFormat, ...);
94
95 /** Sends info to the logfile with extra information, including the files
96 * that it was called from and the line in the code. Besides that, it's
97 * exactly the same as Log. Please use the LineLog macro to make DetailLog
98 * really easy to use. It operates exacly like Log, but inserts the
99 * builtin macros as the lpFile and nLine parameters.
100 *@param nLevel The type of data being logged (error, info, etc.)
101 *@param lpFile The name of the file that called the log function.
102 *@param nLine The line in the file that this log function was called from.
103 *@param lpFunction The name of the function that called the log function.
104 *@param lpFormat The data to send to the log.
105 *@author Mike Buland
106 */
107 void DetailLog( int nLevel, const char *lpFile, int nLine, const char *lpFunction, const char *lpFormat, ...);
108
109 /** Gets a pointer to the only instantion of the MultiLog that can exist.
110 * If there is no instantion in existance, it creates one, so it's
111 * foolproof.
112 *@returns A pointer to the only MultiLog instantion.
113 *@author Mike Buland
114 */
115 static MultiLog *getLog();
116
117 /** Performs standard cleanup and deletes the only instantiation of MultiLog
118 * that can exist. This is just the same as delete and will nicely close
119 * all open logs. always call this when you are done with your MultiLog.
120 */
121 static void cleanup();
122
123 /**
124 * Adds a logging channel to the MultiLog channel chain. Every added
125 * channel will automatically receive a complete log of everything that
126 * happened before the channel was added as well as all future messages.
127 *@param pChannel A pointer to the pre-contructed channel object to add.
128 */
129 void addChannel( class MultiLogChannel *pChannel );
130
131 /** The various pre-defined levels available to use when logging.
132 * The person logging can make up their own, just make sure to remember
133 * which value is which (all levels are integers).
134 *@author Mike Buland
135 */
136 enum Levels
137 {
138 LError,
139 LWarning,
140 LInfo,
141 LStatus
142 };
143};
144
145#endif