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