File: logger.h.html

package info (click to toggle)
rudiments 0.31-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,516 kB
  • ctags: 3,248
  • sloc: asm: 23,776; cpp: 22,792; sh: 7,769; ansic: 1,769; makefile: 1,054; xml: 169; perl: 19
file content (148 lines) | stat: -rw-r--r-- 10,598 bytes parent folder | download | duplicates (2)
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">&lt;rudiments/private/loggerincludes.h&gt;</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">&lt;rudiments/private/logdestination.h&gt;</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 &amp;f);
                syslogdestination       &amp;<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> syslogdestination &amp;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">&lt;rudiments/private/syslogdestination.h&gt;</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 &amp;f);
                filedestination &amp;<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> filedestination &amp;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">&lt;rudiments/private/filedestination.h&gt;</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">&lt;rudiments/private/stdoutdestination.h&gt;</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">&lt;rudiments/private/stderrdestination.h&gt;</font>
};


<font color="#2e8b57"><b>typedef</b></font> linkedlist&lt;logdestination *&gt;            loggerlist;
<font color="#2e8b57"><b>typedef</b></font> linkedlistnode&lt;logdestination *&gt;        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 &quot;logdest&quot; 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 &quot;logdest&quot; 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 &quot;name&quot;, 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 &quot;header&quot;, followed by &quot;tabs&quot; tabs, followed</font>
                        <font color="#0000ff">// by &quot;string&quot; 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 &quot;header&quot;, followed by &quot;tabs&quot; tabs, followed</font>
                        <font color="#0000ff">// by &quot;character&quot; 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 &quot;header&quot;, followed by &quot;tabs&quot; tabs, followed</font>
                        <font color="#0000ff">// by &quot;number&quot; 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 &quot;header&quot;, followed by &quot;tabs&quot; tabs, followed</font>
                        <font color="#0000ff">// by &quot;number&quot; as a single log entry.</font>

<font color="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/logger.h&gt;</font>
};

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>

<font color="#a020f0">#endif</font>
</pre>
</body>
</html>