2 Copyright 2004-2005 Chris Tallon
3 Copyright 2003-2004 University Of Bradford
5 This file is part of VOMP.
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.
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.
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.
26 Log* Log::instance = NULL;
43 Log* Log::getInstance()
48 void Log::upLogLevel()
50 if (logLevel == Log::DEBUG)
52 log("Log", logLevel, "Log level is at its highest already");
57 log("Log", logLevel, "Log level is now %i", logLevel);
60 void Log::downLogLevel()
62 if (logLevel == Log::CRAZY)
64 log("Log", logLevel, "Log level is at its lowest already");
69 log("Log", logLevel, "Log level is now %i", logLevel);
72 int Log::init(int startLogLevel, char* fileName, int tenabled)
75 logLevel = startLogLevel;
77 // logfile = fopen(fileName, "a");
78 // logfile = fopen(stdout, "a");
80 // logfile = fopen("/log", "a");
82 if (logfile) return 1;
88 if (!initted) return 1;
89 if (enabled) fclose(logfile);
93 int Log::log(char *fromModule, int level, char* message, ...)
95 if (!instance || !logfile) return 0;
97 if (!enabled && !netLog) return 1;
98 if (level > logLevel) return 1;
105 gettimeofday(&tv, NULL);
106 struct tm* tms = localtime(&tv.tv_sec);
110 struct tm* tms = localtime(&tb.time);
112 spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tms);
114 spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
116 spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tb.millitm);
119 char levelString[10];
120 if (level == CRAZY) strcpy(levelString, "[CRAZY] ");
121 if (level == EMERG) strcpy(levelString, "[EMERG] ");
122 if (level == ALERT) strcpy(levelString, "[ALERT] ");
123 if (level == CRIT) strcpy(levelString, "[CRIT] ");
124 if (level == ERR) strcpy(levelString, "[ERR] ");
125 if (level == WARN) strcpy(levelString, "[WARN] ");
126 if (level == NOTICE) strcpy(levelString, "[notice]");
127 if (level == INFO) strcpy(levelString, "[info] ");
128 if (level == DEBUG) strcpy(levelString, "[debug] ");
131 spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%s %d %s - ", levelString, getpid(), fromModule);
133 spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%s %s - ", levelString, fromModule);
137 va_start(ap, message);
138 spaceLeft = VSNPRINTF(&buffer[150-spaceLeft], spaceLeft, message, ap);
141 int messageLength = strlen(buffer);
142 if (messageLength < 150)
144 buffer[messageLength] = '\n';
145 buffer[messageLength+1] = '\0';
156 success = fputs(buffer, logfile);
160 if (netLog) vdr->networkLog(buffer);
171 if (instance && logfile) return 1;
177 vdr = VDR::getInstance();
179 log("Log", Log::DEBUG, "Network logging started");
182 void Log::netLogOff()