• Main Page
  • Packages
  • Classes
  • Files
  • File List
  • File Members

unlock/bci/acquire-c++/Logger.hpp

Go to the documentation of this file.
00001 
00002 // Copyright (c) James Percent and Unlock contributors.
00003 // All rights reserved.
00004 // Redistribution and use in source and binary forms, with or without modification,
00005 // are permitted provided that the following conditions are met:
00006 //
00007 //    1. Redistributions of source code must retain the above copyright notice,
00008 //       this list of conditions and the following disclaimer.
00009 //    
00010 //    2. Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //
00014 //    3. Neither the name of Unlock nor the names of its contributors may be used
00015 //       to endorse or promote products derived from this software without
00016 //       specific prior written permission.
00017 
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 
00029 #ifndef LOGGER_HPP
00030 #define LOGGER_HPP
00031 
00032 #include <boost/thread.hpp>
00033 #include <fstream>
00034 #include <string>
00035 #include <stdint.h>
00036 
00037 #include "Portability.hpp"
00038 
00039 class DllExport Logger {
00040 public:
00041     static const int CONSOLE=0x1;
00042     static const int FILE=0x2;
00043     static const int SYNC=0x4;
00044     
00045     static const std::string currentDateTime();
00046     static double currentTimeMilliSecs();
00047     static double currentTimeMicroSecs();
00048     
00049 public:
00050     Logger(const std::string& name);
00051     virtual ~Logger();
00052     void setMode(uint8_t mode);
00053     
00054     void debug(const std::string& msg);
00055     void info(const std::string& msg);
00056     void warn(const std::string& msg);
00057     void error(const std::string& msg);
00058     void fatal(const std::string& msg);
00059 
00060 private:
00061     void logit(const std::string& prefix, const std::string& msg, std::ostream& out, uint8_t mode);
00062     void tryOpen();
00063     
00064 private:
00065     boost::mutex mMutex;
00066     std::ofstream mLog;
00067     std::string mName;
00068     uint8_t mMode;
00069     bool mOpened;
00070 };
00071 
00072 #define logError(msg) error(msg)
00073 #define logFatal(msg) fatal(msg)
00074     
00075 #ifdef NPL_DEBUG
00076     #define logDebug(msg) debug(msg)
00077     #define logInfo(msg) info(msg)
00078     #define logWarn(msg) debug(msg)
00079 #elif NPL_INFO
00080     #define logDebug(msg) 
00081     #define logInfo(msg) info(msg)
00082     #define logWarn(msg) warn(msg)
00083 #elif NPL_WARN
00084     #define logDebug(msg) 
00085     #define logInfo(msg) 
00086     #define logWarn(msg) warn(msg)
00087 #endif
00088 
00089 #endif

Generated on Mon Nov 10 2014 11:09:07 for The Unlock Project by  doxygen 1.7.1