EMAN2
log.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__log__h__
33#define eman__log__h__ 1
34
35#include <cstdarg>
36#include <string>
37
38using std::string;
39
40namespace EMAN
41{
42#if 1
43#ifndef __func__
44#define __func__ ""
45#endif
46#endif
47
48#define ENTERFUNC LOGDEBUG("Enter ")
49#define EXITFUNC LOGDEBUG("Exit ")
50
51#define LOGERR Log::logger()->loc(Log::ERROR_LOG, __FILE__, __LINE__, __func__); Log::logger()->error
52
53#define LOGWARN Log::logger()->loc(Log::WARNING_LOG, __FILE__, __LINE__, __func__); Log::logger()->warn
54
55#define LOGDEBUG Log::logger()->loc(Log::DEBUG_LOG, __FILE__, __LINE__, __func__); Log::logger()->debug
56
57#define LOGVAR Log::logger()->loc(Log::VARIABLE_LOG, __FILE__, __LINE__, __func__); Log::logger()->variable
58
59
68 class Log
69 {
70 public:
72 {
73 ERROR_LOG, // error message
74 WARNING_LOG, // warning message
75 DEBUG_LOG, // debug message, usually at function level.
76 VARIABLE_LOG // very-detailed-level debug message
77 };
78
79 public:
80 static Log *logger();
81
83 int begin(int argc, char *argv[], int ppid);
84 void end(int ref, const string& file = "-", const string& text ="");
85
88 void error(const char *format, ...);
89
92 void warn(const char *format, ...);
93
96 void debug(const char *format, ...);
97
100 void variable(const char *format, ...);
101
102 void set_level(int level);
103
107 void set_logfile(const char *filename);
108
109 void loc(LogLevel level, const string & file, int linenum, const string & func);
110
111 private:
112 Log();
113 Log(const Log &);
114 ~Log();
115
116 void vlog(const char *format, LogLevel level, va_list arg);
117
118 static Log *instance;
119 FILE *out;
123 string location;
124 };
125}
126
127#endif
Log defines a way to output logging information.
Definition: log.h:69
void end(int ref, const string &file="-", const string &text="")
Definition: log.cpp:235
void debug(const char *format,...)
log a debug message.
Definition: log.cpp:140
void vlog(const char *format, LogLevel level, va_list arg)
Definition: log.cpp:100
static Log * instance
Definition: log.h:118
~Log()
Definition: log.cpp:70
string default_emandir
Definition: log.h:121
LogLevel log_level
Definition: log.h:120
void set_level(int level)
Definition: log.cpp:165
void loc(LogLevel level, const string &file, int linenum, const string &func)
Definition: log.cpp:88
int begin(int argc, char *argv[], int ppid)
begin() and start() are used by command-line programs
Definition: log.cpp:177
void error(const char *format,...)
log an error message.
Definition: log.cpp:156
string default_emanlog
Definition: log.h:122
static Log * logger()
Definition: log.cpp:80
void warn(const char *format,...)
log a warning message.
Definition: log.cpp:148
void set_logfile(const char *filename)
set log output file.
Definition: log.cpp:170
string location
Definition: log.h:123
void variable(const char *format,...)
log a very-detailed-level debug message.
Definition: log.cpp:132
LogLevel
Definition: log.h:72
@ WARNING_LOG
Definition: log.h:74
@ DEBUG_LOG
Definition: log.h:75
@ ERROR_LOG
Definition: log.h:73
@ VARIABLE_LOG
Definition: log.h:76
FILE * out
Definition: log.h:119
Log()
Definition: log.cpp:49
E2Exception class.
Definition: aligner.h:40