2
* Copyright (C) 1998-2001 Luca Deri <deri@ntop.org>
3
* Portions by Stefano Suin <stefano@ntop.org>
7
* This program 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
* This program 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 this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
static GDBM_FILE logDB;
29
/* *************************** */
31
void initLogger(void) {
34
if(snprintf(tmpBuff, sizeof(tmpBuff), "%s/logger.db",dbPath) < 0)
35
traceEvent(TRACE_ERROR, "Buffer overflow!");
36
logDB = gdbm_open (tmpBuff, 0, GDBM_NEWDB, 00664, NULL);
40
/* *************************** */
42
void termLogger(void) {
46
accessMutex(&gdbmMutex, "termLogger");
50
releaseMutex(&gdbmMutex);
57
/* *************************** */
59
void logMessage(char* message, u_short severity) {
62
datum key_data, data_data;
65
if((message == NULL) || (logDB == NULL))
68
memset(&msg, 0, sizeof(LogMessage));
69
msg.severity = severity;
70
len = strlen(message);
72
if(len > MESSAGE_MAX_LEN) len = MESSAGE_MAX_LEN;
73
strncpy(msg.message, message, len);
74
msg.message[len]= '\0';
76
if(snprintf(tmpStr, sizeof(tmpStr), "%lu", time(NULL)) < 0)
77
traceEvent(TRACE_ERROR, "Buffer overflow!");
78
key_data.dptr = tmpStr; key_data.dsize = strlen(key_data.dptr)+1;
79
data_data.dptr = (char*)&msg; data_data.dsize = sizeof(LogMessage)+1;
82
accessMutex(&gdbmMutex, "logMessage");
84
gdbm_store(logDB, key_data, data_data, GDBM_REPLACE);
86
releaseMutex(&gdbmMutex);
90
void logMessage(char* message, u_short severity) {
91
traceEvent(TRACE_INFO,"%s [severity %d]\n", message, severity);