/users/dtb26/GITROOT/vetsim/vs-core/include/logger.h

Go to the documentation of this file.
00001 
00010 /*
00011 * AUTHOR    : David Brooks (dtb@iplatypus.org)
00012 * VERSION   : 3.x series
00013 * PLATFORM  : non-specific
00014 * DATE      : 4/15/2012 9:42:57 AM
00015 * COPYRIGHT : Copyright(c)2012, David Brooks,  All Rights Reserved
00016 *
00017 * File      : $Source:$
00018 * Revision  : $Revision:$
00019 * Author    : $Author:$
00020 * Date      : $Date:$
00021 * Tag name  : $Name:$
00022 * Locker    : $Locker:$
00023 * State     : $State: Exp $
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 };//eoc logger
00234 }//eon iplatypus
00235 
00236 
00237 #endif /*LOGGER_H_INCLUDED*/
00238 

Generated on Wed Nov 14 12:01:01 2012 for VetSim Applications by  doxygen 1.4.7