00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef LOGGER_H_INCLUDED
00026 #define LOGGER_H_INCLUDED
00027
00028 #include <fstream>
00029 #include <string>
00030 #include "boost/filesystem.hpp"
00031 #include "boost/interprocess/sync/file_lock.hpp"
00032 #include "boost/interprocess/sync/scoped_lock.hpp"
00033 #include <ctime>
00034
00035 #ifdef NULLPTR
00036 #undef NULLPTR
00037 #endif
00038 #define NULLPTR 0
00039
00040 namespace iplatypus {
00041
00042 const unsigned int LOGGER_MAX_FLAGS = 5;
00043
00053 class logger {
00054 public:
00060 typedef enum log_t { debug = 0, info, warn, error, fatal } priority;
00061
00072 static logger * instance(const std::string & src, const log_t level = warn);
00073
00085 static logger * instance(const std::string & src, const std::string & homedir, const log_t level = warn);
00086
00094 inline static void terminate(void) { if( instance_ ) delete instance_; instance_ = NULLPTR; }
00095
00108 void bind(const log_t lt, const std::string& to_file = CONSOLE);
00109
00119 void bind_specific(const log_t lt, const std::string& to_file = CONSOLE);
00120
00130 inline void log_level(const log_t newlevel) { this->log_level_ = newlevel; }
00131
00140 inline const log_t log_level(void) const { return(this->log_level_); }
00141
00156 void write(const log_t lt, const std::string& msg);
00157
00168 void write(const std::string & srcfile, const log_t lt, const std::string& msg);
00169
00176 inline void write_debug(const std::string & msg) { this->write(debug, msg); }
00177
00184 inline void write_info(const std::string & msg) { this->write(info, msg); }
00185
00192 inline void write_warn(const std::string & msg) { this->write(warn, msg); }
00193
00200 inline void write_error(const std::string & msg) { this->write(error, msg); }
00201
00208 inline void write_fatal(const std::string & msg) { this->write(fatal, msg); }
00209
00210 protected:
00212 logger(void){;}
00213 logger(const std::string & src, const log_t level = warn);
00214 logger(const std::string & src, const std::string & homedir, const log_t level = warn);
00215 virtual ~logger(void){ if(logs_){logs_->clear(); delete logs_; logs_ = NULL;}}
00216 logger(const logger & refcpy){;}
00217 std::string timestamp(void);
00218
00219
00220 private:
00221 const static std::string CONSOLE;
00222 const static std::string DFLTDIR;
00223 const static std::string DFLTFILE;
00224 const static std::string FLAGSTR[LOGGER_MAX_FLAGS];
00225
00226 bool dir_defined_;
00227 log_t log_level_;
00228 static logger* instance_;
00229 std::string home_dir_;
00230 std::string src_file_;
00231 std::vector<std::string>* logs_;
00233 };
00234 }
00235
00236
00237 #endif
00238