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 141 142 143 144 145 146 147 148
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/logger.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2002 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_LOGGER_H</font>
<font color="#a020f0">#define RUDIMENTS_LOGGER_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/loggerincludes.h></font>
<font color="#0000ff">// The logger class and associated logdestination classes provide methods for</font>
<font color="#0000ff">// logging data from an application. The following destinations are supported:</font>
<font color="#0000ff">// file, syslog, stdout and stderr</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// To use these classes: instantiate one or more logdestinations,</font>
<font color="#0000ff">// instantiate a logger, and add the logdestination instance(s) to the</font>
<font color="#0000ff">// logger class instance using addLogDestination(). Then, each call to a</font>
<font color="#0000ff">// logger class method will output logging information to each of the</font>
<font color="#0000ff">// logdestinations in seqence.</font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#0000ff">// The logdestination class is a virtual base class that just defines methods</font>
<font color="#0000ff">// that the real logdestination classes must implement.</font>
<font color="#2e8b57"><b>class</b></font> logdestination {
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/logdestination.h></font>
};
<font color="#0000ff">// The syslogdestination class writes log data to syslog.</font>
<font color="#2e8b57"><b>class</b></font> syslogdestinationprivate;
<font color="#2e8b57"><b>class</b></font> syslogdestination : <font color="#a52a2a"><b>public</b></font> logdestination {
<font color="#a52a2a"><b>public</b></font>:
syslogdestination();
syslogdestination(<font color="#2e8b57"><b>const</b></font> syslogdestination &f);
syslogdestination &<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> syslogdestination &f);
<font color="#2e8b57"><b>virtual</b></font> ~syslogdestination();
<font color="#2e8b57"><b>void</b></font> open(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *ident, <font color="#2e8b57"><b>int</b></font> option,
<font color="#2e8b57"><b>int</b></font> facility, <font color="#2e8b57"><b>int</b></font> priority);
<font color="#2e8b57"><b>void</b></font> close();
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/syslogdestination.h></font>
};
<font color="#0000ff">// The filedestination class writes log data to a file.</font>
<font color="#2e8b57"><b>class</b></font> filedestinationprivate;
<font color="#2e8b57"><b>class</b></font> filedestination : <font color="#a52a2a"><b>public</b></font> logdestination {
<font color="#a52a2a"><b>public</b></font>:
filedestination();
filedestination(<font color="#2e8b57"><b>const</b></font> filedestination &f);
filedestination &<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> filedestination &f);
<font color="#2e8b57"><b>virtual</b></font> ~filedestination();
<font color="#2e8b57"><b>bool</b></font> open(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *filename);
<font color="#2e8b57"><b>void</b></font> close();
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/filedestination.h></font>
};
<font color="#0000ff">// The stdoutdestination class writes log data to standard output.</font>
<font color="#2e8b57"><b>class</b></font> stdoutdestination : <font color="#a52a2a"><b>public</b></font> logdestination {
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/stdoutdestination.h></font>
};
<font color="#0000ff">// The stderrdestination class writes log data to standard error.</font>
<font color="#2e8b57"><b>class</b></font> stderrdestination : <font color="#a52a2a"><b>public</b></font> logdestination {
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/stderrdestination.h></font>
};
<font color="#2e8b57"><b>typedef</b></font> linkedlist<logdestination *> loggerlist;
<font color="#2e8b57"><b>typedef</b></font> linkedlistnode<logdestination *> loggerlistnode;
<font color="#0000ff">// The logger class provides methods for managing</font>
<font color="#0000ff">// logdestinations and writing log entries.</font>
<font color="#2e8b57"><b>class</b></font> loggerprivate;
<font color="#2e8b57"><b>class</b></font> logger {
<font color="#a52a2a"><b>public</b></font>:
logger();
~logger();
<font color="#0000ff">// These methods add or remove logdestinations.</font>
<font color="#2e8b57"><b>void</b></font> addLogDestination(logdestination *logdest);
<font color="#0000ff">// Add "logdest" to the list of destinations that</font>
<font color="#0000ff">// log entries will be written to.</font>
<font color="#2e8b57"><b>void</b></font> removeLogDestination(logdestination *logdest);
<font color="#0000ff">// Remove "logdest" from the list of destinations that</font>
<font color="#0000ff">// log entries will be written to.</font>
<font color="#2e8b57"><b>void</b></font> removeAllLogDestinations();
<font color="#0000ff">// Remove all entries from the list of destinations that</font>
<font color="#0000ff">// log entries will be written to.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>char</b></font> *logHeader(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *name);
<font color="#0000ff">// Returns a string containing the current date,</font>
<font color="#0000ff">// followed by "name", followed by the process id in</font>
<font color="#0000ff">// brackets. For example:</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// 01/05/2002 12:54:23 myprogram [2421]</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that this method allocates a string internally</font>
<font color="#0000ff">// and returns it. This string must be deleted by the</font>
<font color="#0000ff">// calling program.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that this method uses getSystemDateAndTime()</font>
<font color="#0000ff">// from the datetime class. If you are using</font>
<font color="#0000ff">// logHeader() in a multi-threaded application, you</font>
<font color="#0000ff">// must supply a mutex to the datetime class using it's</font>
<font color="#0000ff">// setTimeMutex() method.</font>
<font color="#0000ff">// These methods write log entries to each</font>
<font color="#0000ff">// logdestination in sequence.</font>
<font color="#2e8b57"><b>void</b></font> write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *header, <font color="#2e8b57"><b>int32_t</b></font> tabs,
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
<font color="#0000ff">// Writes "header", followed by "tabs" tabs, followed</font>
<font color="#0000ff">// by "string" as a single log entry.</font>
<font color="#2e8b57"><b>void</b></font> write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *header, <font color="#2e8b57"><b>int32_t</b></font> tabs, <font color="#2e8b57"><b>char</b></font> character);
<font color="#0000ff">// Writes "header", followed by "tabs" tabs, followed</font>
<font color="#0000ff">// by "character" as a single log entry.</font>
<font color="#2e8b57"><b>void</b></font> write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *header, <font color="#2e8b57"><b>int32_t</b></font> tabs, <font color="#2e8b57"><b>int32_t</b></font> number);
<font color="#0000ff">// Writes "header", followed by "tabs" tabs, followed</font>
<font color="#0000ff">// by "number" as a single log entry.</font>
<font color="#2e8b57"><b>void</b></font> write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *header, <font color="#2e8b57"><b>int32_t</b></font> tabs, <font color="#2e8b57"><b>double</b></font> number);
<font color="#0000ff">// Writes "header", followed by "tabs" tabs, followed</font>
<font color="#0000ff">// by "number" as a single log entry.</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/logger.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|