CARMA C++
Logger.h
1 #ifndef SZA_UTIL_LOGGER_H
2 #define SZA_UTIL_LOGGER_H
3 
11 #include <string>
12 #include <pthread.h> // Needed for POSIX thread function calls
13 
14 #define LOG_HANDLER_FN(fn) void (fn)(std::string logStr)
15 
16 #include "carma/szautil/LogFile.h"
17 #include "carma/szautil/Mutex.h"
18 
19 namespace sza {
20  namespace util {
21 
22  class LogStream;
23 
24  class Logger {
25  public:
26 
30  virtual ~Logger();
31 
35  static void log(std::string message, bool isError);
36  static void log(LogStream* ls);
40  static void dispatch(std::string message, bool isError);
41  static void dispatch(LogStream* ls);
42 
46  static void report(std::string message, bool isError);
47  static void report(LogStream* ls);
48 
52  static void installLogHandler(LOG_HANDLER_FN(*logHandler));
53 
57  static void installErrHandler(LOG_HANDLER_FN(*errHandler));
58 
62  static void setPrefix(std::string prefix);
63 
67  static void setLogFilePrefix(const std::string& prefix);
68 
72  static void setLogFileDirectory(const std::string& dir);
73 
77  static void openLogFile();
78 
82  static void closeLogFile();
83 
84  /*
85  * Install a default print function for printing to stdout
86  */
87  static void installStdoutPrintFn(LOG_HANDLER_FN(*stdoutPrintFn));
88  static void installStderrPrintFn(LOG_HANDLER_FN(*stderrPrintFn));
89 
90  static void defaultStdoutPrintFn(std::string str);
91  static void defaultStderrPrintFn(std::string str);
92 
93  static void printToStdout(std::string message);
94  static void printToStderr(std::string message);
95 
96  private:
97 
101  Logger();
102 
103  static LOG_HANDLER_FN(*logHandler_);
104  static LOG_HANDLER_FN(*errHandler_);
105 
106  static LOG_HANDLER_FN(*stdoutPrintFn_);
107  static LOG_HANDLER_FN(*stderrPrintFn_);
108 
109  static std::string prefix_;
110 
111  static bool haveLogFile_;
112  static LogFile logFile_;
113 
118  static Mutex guard_;
119  static void write(const std::string& message, bool isError, bool dispatch, bool log);
120 
121  }; // End class Logger
122 
123  } // End namespace util
124 } // End namespace sza
125 
126 
127 
128 #endif // End #ifndef SZA_UTIL_LOGGER_H
Tagged: Mon May 10 17:23:41 PDT 2004.
Tagged: Sat Mar 27 16:28:13 PST 2004.