1 #ifndef REMOTE_UTIL_LOG_H
2 #define REMOTE_UTIL_LOG_H
6 namespace remote
{ namespace util
{
10 /** Log level specifiers
12 * The following log levels can be used to specify the default
13 * log level when opening a log. They are listed in the order
14 * of priority starting with the most important. When
15 * specifying the log level, messages with higher priorities
16 * are automatically included, e.g. Log::INFO will include
17 * Log::ERROR and Log::FATAL.
19 * The specifiers all maps internally to syslog priorities as
20 * defined in <syslog.h>.
32 * May be passed when opening a log, to specify that
33 * syslog should be used. E.g.:
35 * Log::open("remote-mch", Log::INFO, Log::SYSLOG);
37 static const FILE *SYSLOG
;
41 * Configures the various logging options and prepares
42 * for future calls to redirect messages to the
45 * The log file is an ordinary file handle. It should be
46 * a file opened in append mode. To use syslog, pass NULL.
47 * The default is to use stdout.
49 * @param ident A unique log identifier
50 * @param level The default log level, messages
51 * with log level of lower importance
52 * than this will be discarded.
53 * @param file The log file handle.
55 static void open(const char *ident
, int level
= Log::INFO
,
56 const FILE *file
= stdout
);
58 /** Fatal error message
60 * An emergency condition occurred rendering the system
63 static void fatal(const char *format
, ...);
67 * An error condition occurred.
69 static void error(const char *format
, ...);
73 * An warning condition occurred.
75 static void warn(const char *format
, ...);
77 /** Informational message
79 * A normal and non-significant condition occurred.
81 static void info(const char *format
, ...);
85 * For logging occurrences relevant during debuging.
87 static void debug(const char *format
, ...);
90 static void put(int priority
, const char *format
, va_list params
);
91 static const char *ident
;
92 static const FILE *file
;
95 static inline bool use_syslog()
97 return Log::file
== SYSLOG
;
100 /* This might be a bad hardcoded way to discard messages of
101 * less importance. However, the BSD syslog.h file used by
102 * glibc states that EMERG < ERR < WARNING < INFO < DEBUG. */
103 static inline bool ignore(int priority
)
105 return priority
> Log::level
;