openModeller  Version 1.5.0
Log.hh
Go to the documentation of this file.
1 
28 #ifndef _LOGHH_
29 #define _LOGHH_
30 
32 #include <openmodeller/om_defs.hh>
33 
34 #include <iostream>
35 #include <fstream>
36 #include <string>
37 #include <stdarg.h>
38 #include <stdio.h>
39 
40 /****************************************************************/
41 /****************************** Log *****************************/
42 
48 class dllexp Log
49 {
50  public:
52  static Log * instance();
53 
54  typedef enum {
55  Debug =0,
56  Default =1,
57  Info =2,
58  Warn =3,
59  Error =4
60  } Level;
61 
62 #ifndef SWIG
63  class LogCallback {
64  public:
65  virtual ~LogCallback(){};
66  virtual void operator()( Level level, const std::string& msg ) = 0;
67  };
68 
69  class OstreamCallback : public LogCallback {
70  public:
71  OstreamCallback( std::ostream& os );
72  void operator()( Level level, const std::string& msg );
73  private:
74  std::ostream& os;
75  };
76 #endif
77 
78  protected:
82  Log( );
83 
84  public:
85 
87  static std::string format( const char *fmt, ... );
88 
89  ~Log();
90 
97  void set( Level level, std::string fileName, char const *pref="" );
98 
104  void setCallback( LogCallback *lc );
105 
107  void setLevel( Level level ) { _level = level; }
108 
110  void setPrefix( const char *pref );
111 
112  void debug( const char *format, ... );
113  void info ( const char *format, ... );
114  void warn ( const char *format, ... );
115  void error( const char *format, ... );
116 
118  void operator()( const char *format, ... );
119 
120  private:
121 
122  //write log out to callback
123  void FormatAndWrite( Log::LogCallback& lc, Log::Level level, std::string pref, const char* format, va_list ap );
124 
125  static Log * mpInstance;
126 
128 
130 
131  std::string _pref;
132 
133  bool _deleteCallback; // flag indicating if the callback should be deleted by Log
134 };
135 
136 #endif
137 
Level _level
Definition: Log.hh:129
Definition: Log.hh:48
bool _deleteCallback
Definition: Log.hh:133
std::string _pref
Definition: Log.hh:131
Level
Definition: Log.hh:54
void setLevel(Level level)
Definition: Log.hh:107
LogCallback * callback
Definition: Log.hh:127
std::ostream & os
Definition: Log.hh:74
static Log * mpInstance
Definition: Log.hh:125
virtual ~LogCallback()
Definition: Log.hh:65
static char error[256]
Definition: FileParser.cpp:42