# MI - Fimex: include/fimex/Logger.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

# include/fimex/Logger.h

Go to the documentation of this file.

    00001 /*
    00002  * Fimex
    00003  *
    00004  * (C) Copyright 2008, met.no
    00005  *
    00006  * Project Info:  https://wiki.met.no/fimex/start
    00007  *
    00008  * This library is free software; you can redistribute it and/or modify it
    00009  * under the terms of the GNU Lesser General Public License as published by
    00010  * the Free Software Foundation; either version 2.1 of the License, or
    00011  * (at your option) any later version.
    00012  *
    00013  * This library is distributed in the hope that it will be useful, but
    00014  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    00015  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    00016  * License for more details.
    00017  *
    00018  * You should have received a copy of the GNU Lesser General Public
    00019  * License along with this library; if not, write to the Free Software
    00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    00021  * USA.
    00022  */
    00023
    00024 #ifndef LOGGER_H_
    00025 #define LOGGER_H_
    00026
    00027 #include <boost/shared_ptr.hpp>
    00028 #include <string>
    00029 #include <sstream>
    00030
    00031 namespace MetNoFimex {
    00032
    00038 class Logger
    00039 {
    00040 public:
    00044     enum LogLevel {
    00045         OFF = 1000,
    00046         FATAL = 900,
    00047         ERROR = 800,
    00048         WARN = 700,
    00049         INFO = 600,
    00050         DEBUG = 500
    00051     };
    00052         Logger(const std::string& className);
    00053         virtual ~Logger();
    00057         virtual bool isEnabledFor(LogLevel level);
    00065     virtual void forcedLog(LogLevel level, const std::string& message, const char* filename, unsigned int lineNumber);
    00066 };
    00067
    00073 extern Logger::LogLevel defaultLogLevel();
    00074 extern void defaultLogLevel(Logger::LogLevel);
    00075
    00082 #define LOG4FIMEX(logger, level, message) { \
    00083     if (logger->isEnabledFor(level)) {\
    00084         std::ostringstream buffer; \
    00085         buffer << message; \
    00086         logger->forcedLog(level, buffer.str(), __FILE__, __LINE__);}}
    00087
    00088 typedef boost::shared_ptr<Logger> LoggerPtr;
    00095 extern LoggerPtr getLogger(const std::string& className);
    00096
    00097 }  // namespace MetNoFimex
    00098
    00099
    00100 #endif /* LOGGER_H_ */