32 time_t
t =
time(NULL);
33 struct tm *local = localtime(&t);
34 if (!local)
return stamp;
36 if (!strftime(localTime,
sizeof(localTime),
"%c",local))
return stamp;
37 struct tm *utc = gmtime(&t);
38 if (!utc)
return stamp;
40 if (!strftime(utcTime,
sizeof(utcTime),
"%Y-%m-%d %H:%M (UTC)",utc))
53 std::ofstream* ofile =
dynamic_cast<std::ofstream*
>(
err);
54 if (ofile && !(ofile->is_open())) {
59 <<
"##################################################" 61 <<
"# ERROR LOG STARTS AT: " << MakeTimeStamp()
63 <<
"##################################################" 87 std::ofstream* ofile =
dynamic_cast<std::ofstream*
>(log);
88 if (ofile && !(ofile->is_open())) {
93 <<
"##################################################" 95 <<
"# LOG STARTS AT: " << MakeTimeStamp()
97 <<
"##################################################" 137 if (name ==
"QuietLevel") {
141 if (name ==
"LogLevel") {
145 if (name ==
"InfoLevel") {
149 if (name ==
"VerboseLevel") {
158 if (name ==
"SilentLevel") {
162 if (name ==
"ErrorLevel") {
166 if (name ==
"SevereLevel") {
170 if (name ==
"WarnLevel") {
174 if (name ==
"DebugLevel") {
178 if (name ==
"TraceLevel") {
185 std::ostream* StreamPointer(
const std::string& name) {
186 if (name ==
"STDCOUT")
return &std::cout;
187 if (name ==
"STDCERR")
return &std::cerr;
188 if (name[0] !=
'"')
return NULL;
189 if (name[name.size()-1] !=
'"')
return NULL;
191 std::ofstream*
output =
new std::ofstream(file.c_str(),
192 std::ios::out|std::ios::app);
193 if (output->is_open())
return output;
197 bool ReadConfigurationFile(
const char*
config) {
198 std::ifstream
input(config);
199 if (!input.is_open())
return false;
204 std::getline(input,line);
205 if (input.eof())
break;
213 std::string::size_type
position = line.find(
"#");
214 if (position != std::string::npos) line.erase(position);
217 line.erase(0,line.find_first_not_of(
"\t "));
220 if (line.size()==0)
continue;
223 position = line.find(
"=");
224 if (position == std::string::npos) {
226 std::cerr <<
"WARNING: " << config <<
":" << inputLine <<
": " 227 <<
"Configuration line missing an '='" 229 std::cerr <<
" Line: <" << cache <<
">" 231 std::cerr <<
" Configuration line has been skip" <<
std::endl;
237 line.erase(position);
240 value.erase(0,value.find_first_not_of(
"\t "));
243 position = value.find_last_not_of(
"\t ");
244 if (position != std::string::npos) value.erase(position+1);
247 position = line.find_last_not_of(
"\t ");
248 if (position != std::string::npos) line.erase(position+1);
251 std::vector<std::string> fields;
253 position = line.find(
".");
254 if (position == std::string::npos) {
255 fields.push_back(line);
258 fields.push_back(line.substr(0,position));
259 line.erase(0,position+1);
263 if (fields.size() == 2
264 && fields[0] ==
"log" 265 && fields[1] ==
"file") {
267 std::ostream*
str = StreamPointer(value);
269 std::cerr <<
"WARNING: " << config <<
":" 271 <<
"Cannot open log stream." 273 std::cerr <<
" Line: <" << cache <<
">" 275 std::cerr <<
" Configuration line has been skip" 281 else if (fields.size() == 2
282 && fields[0] ==
"error" 283 && fields[1] ==
"file") {
285 std::ostream*
str = StreamPointer(value);
287 std::cerr <<
"WARNING: " << config <<
":" 289 <<
"Cannot open error stream." 291 std::cerr <<
" Line: <" << cache <<
">" 293 std::cerr <<
" Configuration line has been skip" 299 else if (fields.size() == 3
300 && fields[0] ==
"log" 301 && fields[1] ==
"default" 302 && fields[2] ==
"level") {
305 if (!TranslateLogLevel(value,level)) {
306 std::cerr <<
"WARNING: " << config <<
":" 308 <<
"Unknown log level name." 310 std::cerr <<
" Line: <" << cache <<
">" 312 std::cerr <<
" Configuration line has been skip" 318 else if (fields.size() == 3
319 && fields[0] ==
"error" 320 && fields[1] ==
"default" 321 && fields[2] ==
"level") {
324 if (!TranslateErrorLevel(value,level)) {
325 std::cerr <<
"WARNING: " << config <<
":" 327 <<
"Unknown error level name." 329 std::cerr <<
" Line: <" << cache <<
">" 331 std::cerr <<
" Configuration line has been skip" 337 else if (fields.size() == 3
338 && fields[0] ==
"log" 339 && fields[2] ==
"level") {
342 if (!TranslateLogLevel(value,level)) {
343 std::cerr <<
"WARNING: " << config <<
":" 345 <<
"Unknown log level name." 347 std::cerr <<
" Line: <" << cache <<
">" 349 std::cerr <<
" Configuration line has been skip" 355 else if (fields.size() == 3
356 && fields[0] ==
"error" 357 && fields[2] ==
"level") {
360 if (!TranslateErrorLevel(value,level)) {
361 std::cerr <<
"WARNING: " << config <<
":" 363 <<
"Unknown error level name." 365 std::cerr <<
" Line: <" << cache <<
">" 367 std::cerr <<
" Configuration line has been skip" 374 std::cerr <<
"WARNING: " << config <<
":" << inputLine <<
": " 375 <<
"Unknown command." 377 std::cerr <<
" Line: <" << cache <<
">" 379 std::cerr <<
" Configuration line has been skip" <<
std::endl;
389 ReadConfigurationFile(
"./edeplog.config");
391 bool success = ReadConfigurationFile(conf);
392 if (!success)
EDepSimLog(
"EDepSim::Log configuration file was not read.");
#define EDepSimLog(outStream)
static void SetIndentation(int i)
Set the indentation level for a log message.
static ErrorPriority GetDebugLevel()
Get the current debugging level;.
static std::ostream & GetLogStream()
Return the stream associated with the log file.
static void SetLogLevel(LogPriority level)
Set the default logging level.
static ErrorPriority fErrorPriority
static std::map< std::string, ErrorPriority > fErrorTraces
static std::string MakeIndent()
[Internal method] Make an indentation for a log message.
static std::map< std::string, LogPriority > fLogTraces
#define EDepSimSevere(outStream)
static LogPriority fLogPriority
static void ResetIndentation()
Reset the indentation to zero.
static std::ostream * fLogStream
M::value_type trace(const M &m)
static void SetLogStream(std::ostream *log)
Set the output stream to be used for log messages.
static void DecreaseIndentation()
Decrease the indentation level.
static int max(int a, int b)
void err(const char *fmt,...)
static void SetDebugLevel(ErrorPriority level)
static void IncreaseIndentation()
Increase the indentation level.
static std::ostream & GetDebugStream()
Return the stream associated with the error file.
void line(double t, double *p, double &x, double &y, double &z)
static void SetDebugStream(std::ostream *err)
Set the output stream to be used for error messages.
static LogPriority GetLogLevel()
Get the current logging level;.
static void Configure(const char *conf=NULL)
static std::ostream * fDebugStream
QTextStream & endl(QTextStream &s)