Cleanup inclusion of system header files for the util module
[remote/remote-mci.git] / src / util / Log.h
blobd360b4cfa3eec3ac2a68709fbe3e45f58ac6baa0
1 #ifndef REMOTE_UTIL_LOG_H
2 #define REMOTE_UTIL_LOG_H
4 #include "remote.h"
6 namespace remote { namespace util {
8 class Log {
9 public:
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>.
22 enum {
23 FATAL = LOG_EMERG,
24 ERROR = LOG_ERR,
25 WARN = LOG_WARNING,
26 INFO = LOG_INFO,
27 DEBUG = LOG_DEBUG,
30 /** Syslog specifier
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;
39 /** Setup logging
41 * Configures the various logging options and prepares
42 * for future calls to redirect messages to the
43 * requested place.
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
61 * unusable.
63 static void fatal(const char *format, ...);
65 /** Error message
67 * An error condition occurred.
69 static void error(const char *format, ...);
71 /** Warning message
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, ...);
83 /** Debug message
85 * For logging occurrences relevant during debuging.
87 static void debug(const char *format, ...);
89 private:
90 static void put(int priority, const char *format, va_list params);
91 static const char *ident;
92 static const FILE *file;
93 static int level;
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;
111 #endif