]> git.vomp.tv Git - vompclient.git/blob - log.h
Compile fix for MVP re: location change of hmsf
[vompclient.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 #ifndef WIN32
27  #include <unistd.h>
28  #include <sys/time.h>
29 #else
30  #include <sys/timeb.h>
31 #endif
32
33 #include <time.h>
34 #include <string.h>
35 #include <stdarg.h>
36 #include <sys/types.h>
37 #include "defines.h"
38
39
40 class ExternLogger {
41 public:
42         virtual bool LogExtern(const char* message)=0;
43 };
44
45
46 class Log
47 {
48   public:
49     Log();
50     ~Log();
51     static Log* getInstance();
52
53     int init(int defaultLevel,const char* fileName, int enabled);
54     int shutdown();
55     int log(const char *fromModule, int level,const char *message, ...);
56     void logLongString(const char *fromModule, int level,const char *message);
57     int status();
58     void upLogLevel();
59     void downLogLevel();
60     void setExternLogger(ExternLogger* log);
61     void unsetExternLogger() {
62         extlog=NULL;
63     }
64
65
66
67     const static int CRAZY  = 0; // mad crazy things that should never happen
68     const static int EMERG  = 1; // human assist required NOW
69     const static int ALERT  = 2; // system unusable, but happy to sit there
70     const static int CRIT   = 3; // still working, but maybe about to die
71     const static int ERR    = 4; // that response is not even listed...
72     const static int WARN   = 5; // this could be a bad thing. still running tho
73     const static int NOTICE = 6; // significant good thing
74     const static int INFO   = 7; // verbose good thing
75     const static int DEBUG  = 8; // debug-level messages
76
77   private:
78     static Log* instance;
79     int initted;
80     int logLevel;
81     int enabled;
82
83     FILE *logfile;
84     
85     ExternLogger* extlog;
86
87
88 };
89
90 #endif
91
92 /*
93
94 Documentation
95 -------------
96
97 This class is intended to be instatiated once by the core.
98 For a one off use:
99
100 Log::getInstance()->log("<module-name>", Log::<levelname>, "<message>");
101
102 Or, a pointer can be stored and used:
103
104 Log *myptr = Log::getInstance();
105
106 myptr->log("<module-name>", Log::<levelname>, "<message>");
107 myptr->log("<module-name>", Log::<levelname>, "<message>");
108
109 Level usages are above.
110
111 The message parameter in the log function can be used in the same way as printf, eg.
112
113 myptr->log("<module-name>", Log::<levelname>, "Success: %s %i", stringpointer, integer);
114
115 */