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