MCS: Use remote.h and cleanup header file inclusion
[remote/remote-mci.git] / libutil / Log.h
blob240d7f3207c7dca341c07ed93fbcf504c3b877da
1 #ifndef REMOTE_UTIL_LOG_H
2 #define REMOTE_UTIL_LOG_H
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <syslog.h>
8 namespace remote { namespace util {
10 class Log {
11 public:
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>.
24 enum {
25 FATAL = LOG_EMERG,
26 ERROR = LOG_ERR,
27 WARN = LOG_WARNING,
28 INFO = LOG_INFO,
29 DEBUG = LOG_DEBUG,
32 /** Syslog specifier
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;
41 /** Setup logging
43 * Configures the various logging options and prepares
44 * for future calls to redirect messages to the
45 * requested place.
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
63 * unusable.
65 static void fatal(const char *format, ...);
67 /** Error message
69 * An error condition occurred.
71 static void error(const char *format, ...);
73 /** Warning message
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, ...);
85 /** Debug message
87 * For logging occurrences relevant during debuging.
89 static void debug(const char *format, ...);
91 private:
92 static void put(int priority, const char *format, va_list params);
93 static const char *ident;
94 static const FILE *file;
95 static int level;
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;
113 #endif