1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
FALCON - The Falcon Programming Language
FILE: logging_srv_syslog.cpp
Logging module -- module service classes
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: Sat, 12 Sep 2009 16:42:41 +0200
-------------------------------------------------------------------
(C) Copyright 2009: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
#include "logging_mod.h"
#include <falcon/error.h>
#include <falcon/autocstring.h>
#include <syslog.h>
namespace Falcon {
LogChannelSyslog::LogChannelSyslog( const String& identity, uint32 facility, int level ):
LogChannel( level ),
m_identity( identity ),
m_facility( facility )
{
init();
}
LogChannelSyslog::LogChannelSyslog( const String& identity, const String &fmt, uint32 facility, int level ):
LogChannel( fmt, level ),
m_identity( identity ),
m_facility( facility )
{
init();
}
LogChannelSyslog::~LogChannelSyslog()
{
stop();
closelog();
}
void LogChannelSyslog::init()
{
if ( m_facility == 0 )
m_facility = LOG_USER;
AutoCString app( m_identity );
openlog( app.c_str() , LOG_NDELAY | LOG_PID, m_facility );
}
void LogChannelSyslog::writeLogEntry( const String& entry, LogMessage* pOrigMsg )
{
int level;
switch( pOrigMsg->m_level )
{
case LOGLEVEL_FATAL: level = LOG_ALERT; break;
case LOGLEVEL_ERROR: level = LOG_ERR; break;
case LOGLEVEL_WARN: level = LOG_WARNING; break;
case LOGLEVEL_INFO: level = LOG_INFO; break;
default: level = LOG_DEBUG; break;
}
AutoCString msg(entry);
syslog( m_facility | level, "%s", msg.c_str() );
}
}
/* end of logging_srv_syslog.cpp */
|