SeaBreeze
Log.h
Go to the documentation of this file.
1 
30 #ifndef SEABREEZE_LOG_H
31 #define SEABREEZE_LOG_H
32 
33 #include "api/DllDecl.h"
34 
35 #include <string>
36 #include <stack>
37 #include <stdio.h>
38 #include <stdarg.h>
39 
40 #ifdef OOI_DEBUG
41  #define OOI_LOG_PRINT 1
42 #else
43  #define OOI_LOG_PRINT 0
44 #endif
45 
46 #ifdef __cplusplus
47 
52 #define LOG(s) Log logger(s);
53 
59 #define LOG_DEBUG(s) do { if (OOI_LOG_PRINT) logger.debug s; } while (0)
60 
62 #define LOG_INFO(s) do { if (OOI_LOG_PRINT) logger.info s; } while (0)
63 
65 #define LOG_WARN(s) do { if (OOI_LOG_PRINT) logger.warn s; } while (0)
66 
68 #define LOG_ERROR(s) do { if (OOI_LOG_PRINT) logger.error s; } while (0)
69 
70 #define OOI_LOG_LEVEL_NEVER 0
71 #define OOI_LOG_LEVEL_ERROR 1
72 #define OOI_LOG_LEVEL_WARN 2
73 #define OOI_LOG_LEVEL_INFO 3
74 #define OOI_LOG_LEVEL_DEBUG 4
75 #define OOI_LOG_LEVEL_TRACE 5
76 
85 class DLL_DECL Log
86 {
87  public:
88  Log(const char *s);
89  ~Log();
90 
91  // public class methods
92  static void setLogLevel(int lvl);
93  static void setLogLevel(const std::string& s);
94  static void setLogFile(void *f);
95 
96  // public instance methods
97  void debug(const char *fmt, ...);
98  void info (const char *fmt, ...);
99  void warn (const char *fmt, ...);
100  void error(const char *fmt, ...);
101 
102  // these must be public for C interface to work
103  static unsigned logLevel;
104  void formatAndSend(int lvl, const char *lvlName,
105  const char *separator, const char *fmt, va_list args);
106 
107  private:
108  // private class attributes
109  static FILE *logFile;
110  static std::stack<std::string>* callstack;
111 
112  // private instance methods
113  void trace(const char *fmt, ...);
114 };
115 
116 extern "C" {
117 #endif /* __cplusplus */
118 
119 // We need the flattened C interface if we want to call from Cygwin (mainly
120 // to set log level)...see http://cygwin.com/ml/cygwin/2006-04/msg00251.html
121 void DLL_DECL seabreeze_log_set_level_int(int lvl);
122 void DLL_DECL seabreeze_log_set_level_string(const char *s);
123 void DLL_DECL seabreeze_log_debug(const char *fmt, ...);
124 void DLL_DECL seabreeze_log_info (const char *fmt, ...);
125 void DLL_DECL seabreeze_log_warn (const char *fmt, ...);
126 void DLL_DECL seabreeze_log_error(const char *fmt, ...);
127 
128 #ifdef __cplusplus
129 };
130 
131 #endif /* __cplusplus */
132 #endif
Simple logger for OOI applications.
Definition: Log.h:85