35 #include <sys/types.h>
41 #ifdef SNMP_PP_NAMESPACE
46 #define ERROR_LOG 0x10
47 #define WARNING_LOG 0x20
48 #define EVENT_LOG 0x30
50 #define DEBUG_LOG 0x50
53 #define LOG_CLASS_MASK 0xF0
54 #define LOG_LEVEL_MASK 0x0F
60 #define LOG_BEGIN(name,level) (void)0
61 #define LOG(item) (void)0
62 #define LOG_END (void)0
68 #define LOG_BEGIN(name,level) \
70 if (DefaultLog::log()->log_needed(name,level)) \
73 DefaultLog::create_log_entry(name,level)
75 #define LOG(item) *DefaultLog::log_entry() += item
78 *DefaultLog::log() += DefaultLog::log_entry(); \
79 DefaultLog::delete_log_entry(); \
80 DefaultLog::unlock(); \
85 #define LOG_UNUSED(x) x
122 LogEntry(
const char *
const n,
unsigned char t) : name(n), type(t), count(0) {}
132 virtual void init(
void);
139 virtual LogEntry& operator+=(
const long);
146 virtual LogEntry& operator+=(
const char*);
153 virtual const char*
get_value(
void)
const {
return ""; }
192 virtual bool add_string(
const char*) = 0;
201 virtual bool add_integer(
long);
206 virtual bool add_timestamp(
void);
217 #define MAX_LOG_SIZE 2550 // increased until debugprintf is not used!
245 output_stopped =
false;
261 virtual const char*
get_value(
void)
const {
return value; }
279 bool add_string(
const char*);
313 #ifdef WITH_LOG_PROFILES
323 virtual void set_profile(
const char *
const logprofile);
333 virtual void set_filter(
int logclass,
unsigned char filter);
340 virtual unsigned char get_filter(
int logclass)
const;
349 virtual LogEntry* create_log_entry(
const char *
const name,
unsigned char t)
const = 0;
370 virtual bool log_needed(
const char *
const,
unsigned char t)
const
371 {
return (logfilter[(t / 16) - 1] != 0xFF) && ((t &
LOG_LEVEL_MASK) <= logfilter[(t / 16) - 1]); }
384 virtual const char* now(
char* = 0);
395 static const char* get_current_time();
442 void set_dest(
const char*);
449 void set_dest(FILE*);
458 virtual LogEntry* create_log_entry(
const char *
const name,
unsigned char)
const;
503 { lock();
if (instance)
delete instance; instance = logger; unlock(); }
526 static void cleanup();
552 entry = log()->create_log_entry(name,t);
613 #ifdef SNMP_PP_NAMESPACE
virtual ~AgentLog()
Virtual destructor.
static void create_log_entry(const char *name, unsigned char t)
Create a new log entry or reuse an existing one.
static void unlock()
Unlock the log singleton.
static const char defaultName
unsigned char get_level() const
Get the level of this log entry.
LogEntry(const char *const n, unsigned char t)
Constructor with log class and severity level.
const char * get_name() const
Get the logger name of this log entry.
The LogEntry class represents log entries.
virtual bool log_needed(const char *const, unsigned char t) const
Check whether a logging for the given type of LogEntry has to be done or not.
The LogEntryImpl class implements a log entry using a dynamically allocated, but fixed-size buffer...
static void lock()
Lock the log singleton.
virtual const char * get_value(void) const
Get the contents of this log entry.
static SnmpSynchronized mutex
unsigned char get_type() const
Get the type of this log entry.
static AgentLog * log()
Return the default logger.
unsigned char get_class() const
Get the class of this log entry.
static void delete_log_entry()
Delete current log entry.
virtual ~LogEntryImpl()
Destructor.
LogEntryImpl(const char *const n, unsigned char t)
Constructor with log class and severity level.
The AgentLogImpl class is an implementation of AgentLog which writes log messages to a file...
unsigned int bytes_left()
Count the bytes left for additional values.
static AgentLog * instance
static void init(AgentLog *logger)
Initialize the default logger with the given logging implementation.
static LogEntry * log_entry()
Return the current log entry.
virtual ~LogEntry()
Virtual destructor.
The AgentLog class is an abstract base class representing a log for information that is generated dur...
virtual const char * get_value(void) const
Get the contents of this log entry.
The DefaultLog class has a static Log member, that is used by the AGENT++ API for logging...