File: log.C

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (59 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download
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
// Copyright (c) 2002  David Muse
// See the file COPYING for more information

#include <rudiments/logger.h>

int main(int argc, const char **argv) {
	
	logger			lg;

	syslogdestination	sd;
	filedestination		fd;
	stdoutdestination	sod;
	stderrdestination	sed;

	// initialize and add a syslog log destination
	sd.open("logtest",LOG_CONS,LOG_USER,LOG_INFO);
	lg.addLogDestination(&sd);

	// initialize and add a file log destination
	fd.open("test.log");
	lg.addLogDestination(&fd);

	// add a standard output log destination
	lg.addLogDestination(&sod);

	// add a standard error log destination
	lg.addLogDestination(&sed);

	// write a string, character, long and float value to the log, along
	// with a standard log header for each
	char	*header=logger::logHeader("logtest");
	lg.write(header,0,"test");
	lg.write(header,0,'t');
	lg.write(header,0,(long)12345);
	lg.write(header,0,123.45);
	delete[] header;

	// remove all log destinations
	lg.removeAllLogDestinations();

	// add each of the log destinations back
	lg.addLogDestination(&sd);
	lg.addLogDestination(&fd);
	lg.addLogDestination(&sod);
	lg.addLogDestination(&sed);

	// remove them one by one
	lg.removeLogDestination(&sd);
	lg.removeLogDestination(&fd);
	lg.removeLogDestination(&sod);
	lg.removeLogDestination(&sed);
	lg.removeAllLogDestinations();

	// close the syslog log destination
	sd.close();

	// close the file log destination
	fd.close();
}