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