Logger.h

Go to the documentation of this file.
00001 /*
00002  * opencog/util/Logger.h
00003  *
00004  * Copyright (C) 2002-2007 Novamente LLC
00005  * Copyright (C) 2008 by Singularity Institute for Artificial Intelligence
00006  * All Rights Reserved
00007  *
00008  * Written by Andre Senna <senna@vettalabs.com>
00009  *            Gustavo Gama <gama@vettalabs.com>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU Affero General Public License v3 as
00013  * published by the Free Software Foundation and including the exceptions
00014  * at http://opencog.org/wiki/Licenses
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program; if not, write to:
00023  * Free Software Foundation, Inc.,
00024  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00025  */
00026 
00027 #ifndef _OPENCOG_LOGGER_H
00028 #define _OPENCOG_LOGGER_H
00029 
00030 #include <string>
00031 
00032 #include <cstdarg>
00033 #include <pthread.h>
00034 
00035 //#undef ERROR
00036 //#undef DEBUG
00037 
00038 namespace opencog
00039 {
00040 
00041 class Logger
00042 {
00043 
00044 public:
00045 
00046     //WARNING: if you change the levels don't forget to update
00047     //levelStrings[] in Logger.cc
00048     enum Level { NONE, ERROR, WARN, INFO, DEBUG, FINE };
00049 
00051     static const Level getLevelFromString(const std::string&);
00052     static const char* getLevelString(const Level);
00053 
00054 
00055     // ***********************************************/
00056     // Constructors/destructors
00057     ~Logger();
00058 
00066     Logger(const std::string &fileName = "opencog.log", Level level = INFO, bool timestampEnabled = true);
00067 
00068     Logger(const Logger&);
00069 
00070     // ***********************************************/
00071     // API
00072 
00077     void setLevel(Level);
00078 
00084     Level getLevel() const;
00085 
00091     void setBackTraceLevel(Level);
00092 
00097     Level getBackTraceLevel() const;
00098 
00099     /* filename property */
00100     void setFilename(const std::string&);
00101     const std::string& getFilename();
00102 
00107     void setTimestampFlag(bool flag);
00108 
00113     void setPrintToStdoutFlag(bool flag);
00114 
00120     void setPrintErrorLevelStdout();
00121 
00126     void log  (Level level, const std::string &txt);
00127     void error(const std::string &txt);
00128     void warn (const std::string &txt);
00129     void info (const std::string &txt);
00130     void debug(const std::string &txt);
00131     void fine (const std::string &txt);
00132 
00139     void logva(Level level, const char *, va_list args);
00140     void log  (Level level, const char *, ...);
00141     void error(const char *, ...);
00142     void warn (const char *, ...);
00143     void info (const char *, ...);
00144     void debug(const char *, ...);
00145     void fine (const char *, ...);
00146 
00152     bool isEnabled(Level level) const;
00153     bool isErrorEnabled() const;
00154     bool isWarnEnabled() const;
00155     bool isInfoEnabled() const;
00156     bool isDebugEnabled() const;
00157     bool isFineEnabled() const;
00158 
00162     void enable();
00163 
00167     void disable();
00168 
00169 private:
00170 
00171     std::string fileName;
00172     bool timestampEnabled;
00173     Level currentLevel;
00174     Level backTraceLevel;
00175     bool logEnabled;
00176     bool printToStdout;
00177     pthread_mutex_t lock;
00178     FILE *f;
00179 
00180 }; // class
00181 
00182 // singleton instance (following meyer's design pattern)
00183 Logger& logger();
00184 
00185 }  // namespace opencog
00186 
00187 #endif // _OPENCOG_LOGGER_H

Generated on Fri Dec 4 23:23:31 2009 for OpenCog Framework by  doxygen 1.5.6