1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org>
2
3 #include "logger.h"
4
5 #include "estring.h"
6 #include "allocator.h"
7
8
9 static Logger *logger = 0;
10
11
12 /*! \class Logger logger.h
13 Abstract base class for things that log messages.
14
15 All subclasses of Logger must implement the send() virtual function,
16 and take responsibility for correctly logging the lines of text that
17 are passed to it.
18
19 A program creates one instance of a Logger subclass at startup and
20 uses Logger::global() to process any messages sent to a Log object
21 thereafter.
22 */
23
24 /*! Stores the address of the newly-created Logger for global(). */
25
Logger()26 Logger::Logger()
27 {
28 ::logger = this;
29 Allocator::addEternal( this, "logger" );
30 }
31
32
33 /*! \fn void Logger::send( const EString &id,
34 Log::Severity s,
35 const EString & m )
36
37 This virtual function logs the message \a m belonging to
38 transaction \a id, whose severity is \a s, in a manner decided by
39 the subclass.
40
41 \a id uniquely identifies a Log object.
42 */
43
44
45 /*! This virtual destructor exists only to ensure that global() doesn't
46 return a bad pointer.
47 */
48
~Logger()49 Logger::~Logger()
50 {
51 ::logger = 0;
52 }
53
54
55 /*! Returns a pointer to the global Logger. */
56
global()57 Logger *Logger::global()
58 {
59 return ::logger;
60 }
61
62
63 /*! Returns an application name. Subclasses must provide this name.
64
65 I don't like this mechanism. It's hacky. Only exists to let Log
66 (in core) get at information held by the Server class (in server).
67 */
68
name() const69 EString Logger::name() const
70 {
71 return "Archiveopteryx";
72 }
73