COVISE Core
coErr.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef _CO_ERR_H_
9#define _CO_ERR_H_
10
11#include "coExport.h"
12#include <stdio.h>
13#include <stdlib.h>
14#include <stdarg.h>
15#include <string>
16
17// 25.02.98
18
23namespace covise
24{
25
27{
28public:
29 static bool init(void);
30 static void destroy(void);
31
32 static void setLogLevels(int lev_console, int lev_file);
33
34 // Methods to log error-, warning- and info-messages. Usage like printf().
35 // the error-level is set with the environment-variables YAC_DEBUG_FILE and YAC_DEBUG_CONSOLE
36 // level set to 0 : nothing gets logged
37 // 1 : only errors
38 // 2 : errors + warnings
39 // 3 : errors + warnings + messages
40 static void error(const char *msg, ...);
41 static void warning(const char *msg, ...);
42 static void info(const char *msg, ...);
43
44 // for use with the macros (current file-name, file-line and the message will get logged)
45 // don't call the following three methods explicitly use LOGERROR, LOGWARNING and LOGINFO instead
46 static void fl_error(const char *msg, ...);
47 static void fl_warning(const char *msg, ...);
48 static void fl_info(const char *msg, ...);
49
50 // ------ old methods ------
51 // print error message
52 static void error(int line, const char *fname, const char *comment);
53 // print warning message
54 static void warning(int line, const char *fname, const char *comment);
55 // print message
56 static void comment(int line, const char *fname, const char *comment);
57 // print message with 1 int parameter
58 static void comment(int line, const char *fname, const char *comment, int i)
59 {
60 char buf[1024];
61 sprintf(buf, comment, i);
62 coErr::comment(line, fname, buf);
63 }
64 // print message with 1 string parameter
65 static void comment(int line, const char *fname, const char *comment, const char *st)
66 {
67 char buf[1024];
68 sprintf(buf, comment, st);
69 coErr::comment(line, fname, st);
70 }
71
72private:
73 // we don't want a copy-constructor
74 coErr(const coErr &);
75 // we don't want an assignment operator
77
78 // file to write data to
79 static FILE *m_file;
80 // file name to use
81 // static char *m_filename;
82 // file logging level: 99: don't know
83 // 0: nothing
84 // 1: only errors
85 // 2: errors + warnings
86 // 3: errors + warnings + messages
87 static int m_file_lev;
88
89 // level to copy messages on stderr (default NO
90 static int m_console_lev;
91};
92}
93// ----- BC: Helper-Function & Macro for Debugging
94// NOTE: For debug messages you may use DBGOUT which behaves like printf (with variable parameter list).
95// Message output goes to the debug output window on windows and stderr on linux
96// Output will only be generated in Debug-Builds (if _DEBUG is defined).
97//
98// WARNING: Since this macro is fragile you should take care when using "if ... else ...". Use brackets { } !!!
99
101extern int UTILEXPORT __MY_LINE__;
102UTILEXPORT void bcHelperDebug(const char *msg, ...);
103
104// DBGOUT - print a debug message only if _DEBUG is defined !
105#ifdef _DEBUG
106// in DEBUG-Builds use the following
107#define DBGOUT \
108 __MY_FILE__ = __FILE__; \
109 __MY_LINE__ = __LINE__; \
110 bcHelperDebug
111#else
112// otherwise replace with "nothing"
113//inline void __dummy_dbgout(const char */*crap*/=NULL, ... ) {}
114inline void __dummy_dbgout(const char *, ...)
115{
116}
117//inline void __dummy_dbgout(std::string &, ... ) {}
118#define DBGOUT 1 ? (void)0 : __dummy_dbgout
119#endif // _DEBUG
120
121// ----- BC: Macros for logging
122// see Note & Warning above
123#ifdef YAC_DONT_LOG
124// replace with "nothing"
125//inline void __dummy_logout(const char *crap=NULL, ... ) {}
126inline void __dummy_logout(const char *, ...)
127{
128}
129#define LOGERROR 1 ? (void)0 : __dummy_logout
130#define LOGWARNING 1 ? (void)0 : __dummy_logout
131#define LOGINFO 1 ? (void)0 : __dummy_logout
132#else
133// Usually do the following
134#define LOGERROR \
135 __MY_FILE__ = __FILE__; \
136 __MY_LINE__ = __LINE__; \
137 covise::coErr::fl_error
138#define LOGWARNING \
139 __MY_FILE__ = __FILE__; \
140 __MY_LINE__ = __LINE__; \
141 covise::coErr::fl_warning
142#define LOGINFO \
143 __MY_FILE__ = __FILE__; \
144 __MY_LINE__ = __LINE__; \
145 covise::coErr::fl_info
146#endif // YAC_DONT_LOG
147
148#endif
void __dummy_dbgout(const char *,...)
Definition: coErr.h:114
UTILEXPORT void bcHelperDebug(const char *msg,...)
Definition: coErr.cpp:39
std::string UTILEXPORT __MY_FILE__
Definition: coErr.cpp:32
int UTILEXPORT __MY_LINE__
Definition: coErr.cpp:33
#define UTILEXPORT
Definition: coExport.h:206
GLsizei const GLchar *const * string
Definition: khronos-glext.h:6750
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: khronos-glext.h:8469
list of all chemical elements
Definition: coConfig.h:27
Definition: coErr.h:27
static FILE * m_file
Definition: coErr.h:79
coErr & operator=(const coErr &)
static void comment(int line, const char *fname, const char *comment, int i)
Definition: coErr.h:58
coErr(const coErr &)
static int m_file_lev
Definition: coErr.h:87
static void comment(int line, const char *fname, const char *comment)
Definition: coErr.cpp:369
static void comment(int line, const char *fname, const char *comment, const char *st)
Definition: coErr.h:65
static int m_console_lev
Definition: coErr.h:90