EMAN2
log.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  * 
00034  * */
00035 
00036 #ifndef eman__log__h__
00037 #define eman__log__h__ 1
00038 
00039 #include <cstdarg>
00040 #include <string>
00041 
00042 using std::string;
00043 
00044 namespace EMAN
00045 {
00046 #if 1
00047 #ifndef __func__
00048 #define __func__ ""
00049 #endif
00050 #endif
00051         
00052 #define ENTERFUNC  LOGDEBUG("Enter ")
00053 #define EXITFUNC   LOGDEBUG("Exit ")
00054         
00055 #define LOGERR Log::logger()->loc(Log::ERROR_LOG, __FILE__, __LINE__, __func__); Log::logger()->error
00056 
00057 #define LOGWARN Log::logger()->loc(Log::WARNING_LOG, __FILE__, __LINE__, __func__); Log::logger()->warn
00058 
00059 #define LOGDEBUG Log::logger()->loc(Log::DEBUG_LOG, __FILE__, __LINE__, __func__); Log::logger()->debug
00060 
00061 #define LOGVAR Log::logger()->loc(Log::VARIABLE_LOG, __FILE__, __LINE__, __func__); Log::logger()->variable
00062         
00063 
00072         class Log
00073         {
00074           public:
00075                 enum LogLevel
00076                 {
00077                         ERROR_LOG,        // error message
00078                         WARNING_LOG,      // warning message
00079                         DEBUG_LOG,        // debug message, usually at function level.
00080                         VARIABLE_LOG      // very-detailed-level debug message
00081                 };
00082 
00083           public:
00084                 static Log *logger();
00085 
00087                 int begin(int argc, char *argv[], int ppid);
00088                 void end(int ref, const string& file = "-", const string& text ="");
00089 
00092                 void error(const char *format, ...);
00093 
00096                 void warn(const char *format, ...);
00097 
00100                 void debug(const char *format, ...);
00101 
00104                 void variable(const char *format, ...);
00105                 
00106                 void set_level(int level);
00107 
00111                 void set_logfile(const char *filename);
00112 
00113                 void loc(LogLevel level, const string & file, int linenum, const string & func);
00114                 
00115           private:
00116                 Log();
00117                 Log(const Log &);
00118                  ~Log();
00119 
00120                 void vlog(const char *format, LogLevel level, va_list arg);
00121 
00122                 static Log *instance;
00123                 FILE *out;
00124                 LogLevel log_level;
00125                 string default_emandir;
00126                 string default_emanlog;
00127                 string location;
00128         };
00129 }
00130 
00131 #endif