1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
24
* General logging class
36
#include "CSStrUtil.h"
40
* The global logging object.
42
CSLog CSL(stdout, CSLog::Warning);
44
void CSLog::getNow(char *buffer, size_t len)
50
if (ticks == (time_t) -1) {
53
fprintf(iStream, "*** ERROR (%d): While getting time\n", err);
54
cs_strcpy(len, buffer, "-- TIME? --");
57
localtime_r(&ticks, <ime);
58
strftime(buffer, len, "%y%m%d %H:%M:%S", <ime);
61
void CSLog::header(CSThread *self, const char *func, const char *file, int line, int level)
67
fprintf(iStream, "%s", buffer);
71
fprintf(iStream, " [Error] ");
74
fprintf(iStream, " [Warning] ");
77
fprintf(iStream, " [Trace] ");
81
fprintf(iStream, " [Note] ");
85
if (self && self->threadName && self->threadName->length() > 0)
86
fprintf(iStream, "%s: ", self->threadName->getCString());
88
cs_format_context(300, buffer, func, file, line);
90
cs_strcat(300, buffer, " ");
91
fprintf(iStream, "%s", buffer);
95
void CSLog::log(CSThread *self, const char *func, const char *file, int line, int level, const char* buffer)
100
if (level > iLogLevel)
105
if (iHeaderPending) {
106
iHeaderPending = false;
107
header(self, func, file, line, level);
109
/* Write until the next \n... */
110
if ((end_ptr = strchr(buffer, '\n'))) {
111
len = end_ptr - buffer;
112
fwrite(buffer, len, 1, iStream);
113
fprintf(iStream, "\n");
115
iHeaderPending = true;
119
len = strlen(buffer);
120
fwrite(buffer, len, 1, iStream);
127
void CSLog::log(CSThread *self, int level, const char *buffer)
129
log(self, NULL, NULL, 0, level, buffer);
132
void CSLog::log(CSThread *self, int level, CSString& wstr)
134
log(self, level, wstr.getCString());
137
void CSLog::log(CSThread *self, int level, CSString* wstr)
139
log(self, level, wstr->getCString());
142
void CSLog::log(CSThread *self, int level, int v)
146
snprintf(buffer, 100, "%d", v);
147
log(self, level, buffer);
150
void CSLog::eol(CSThread *self, int level)
152
log(self, level, "\n");
155
void CSLog::logLine(CSThread *self, int level, const char *buffer)
158
log(self, level, buffer);