]> git.vomp.tv Git - vompclient-marten.git/blob - log.h
Portability
[vompclient-marten.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include "defines.h"
31
32 class Log
33 {
34   public:
35     Log();
36     ~Log();
37     static Log* getInstance();
38
39     int init(int defaultLevel, char* fileName, int enabled);
40     int shutdown();
41     int log(char *fromModule, int level, char *message, ...);
42     int status();
43     void upLogLevel();
44     void downLogLevel();
45
46     const static int CRAZY  = 0; // mad crazy things that should never happen
47     const static int EMERG  = 1; // human assist required NOW
48     const static int ALERT  = 2; // system unusable, but happy to sit there
49     const static int CRIT   = 3; // still working, but maybe about to die
50     const static int ERR    = 4; // that response is not even listed...
51     const static int WARN   = 5; // this could be a bad thing. still running tho
52     const static int NOTICE = 6; // significant good thing
53     const static int INFO   = 7; // verbose good thing
54     const static int DEBUG  = 8; // debug-level messages
55
56   private:
57     static Log* instance;
58     int initted;
59     int logLevel;
60     int enabled;
61
62     FILE *logfile;
63 };
64
65 #endif
66
67 /*
68
69 Documentation
70 -------------
71
72 This class is intended to be instatiated once by the core.
73 For a one off use:
74
75 Log::getInstance()->log("<module-name>", Log::<levelname>, "<message>");
76
77 Or, a pointer can be stored and used:
78
79 Log *myptr = Log::getInstance();
80
81 myptr->log("<module-name>", Log::<levelname>, "<message>");
82 myptr->log("<module-name>", Log::<levelname>, "<message>");
83
84 Level usages are above.
85
86 The message parameter in the log function can be used in the same way as printf, eg.
87
88 myptr->log("<module-name>", Log::<levelname>, "Success: %s %i", stringpointer, integer);
89
90 */