]> git.vomp.tv Git - vompserver.git/blob - log.h
15 years that line of code has been waiting to crash
[vompserver.git] / log.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3     Copyright 2003-2004 University Of Bradford
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21
22 #ifndef LOG_H
23 #define LOG_H
24
25 #include <stdio.h>
26 #include <time.h>
27 #include <sys/time.h>
28 #include <string.h>
29 #include <stdarg.h>
30
31 class Log
32 {
33   public:
34     Log();
35     ~Log();
36     static Log* getInstance();
37
38     int init(int defaultLevel, char* fileName);
39     int shutdown();
40     int log(const char *fromModule, int level, const char *message, ...);
41     void upLogLevel();
42     void downLogLevel();
43
44     const static int CRAZY  = 0; // mad crazy things that should never happen
45     const static int EMERG  = 1; // human assist required NOW
46     const static int ALERT  = 2; // system unusable, but happy to sit there
47     const static int CRIT   = 3; // still working, but maybe about to die
48     const static int ERR    = 4; // that response is not even listed...
49     const static int WARN   = 5; // this could be a bad thing. still running tho
50     const static int NOTICE = 6; // significant good thing
51     const static int INFO   = 7; // verbose good thing
52     const static int DEBUG  = 8; // debug-level messages
53
54   private:
55     static Log* instance;
56     int initted;
57     int logLevel;
58     int enabled;
59
60     FILE *logfile;
61 };
62
63 #endif
64
65 /*
66
67 Documentation
68 -------------
69
70 This class is intended to be instatiated once by the core.
71 For a one off use:
72
73 Log::getInstance()->log("<module-name>", Log::<levelname>, "<message>");
74
75 Or, a pointer can be stored and used:
76
77 Log *myptr = Log::getInstance();
78
79 myptr->log("<module-name>", Log::<levelname>, "<message>");
80 myptr->log("<module-name>", Log::<levelname>, "<message>");
81
82 Level usages are above.
83
84 The message parameter in the log function can be used in the same way as printf, eg.
85
86 myptr->log("<module-name>", Log::<levelname>, "Success: %s %i", stringpointer, integer);
87
88 */