Fawkes API  Fawkes Development Version
fawkes_logger.cpp
1 
2 /***************************************************************************
3  * fawkes_logger.cpp - External predicates that allow the usage of the Logger
4  *
5  * Created: Wed Jul 22 11:25:21 2009
6  * Copyright 2009 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "fawkes_logger.h"
24 
25 #include <core/exception.h>
26 #include <logging/logger.h>
27 #include <plugins/eclipse-clp/eclipse_thread.h>
28 
29 #include <cstdio>
30 #include <cstring>
31 
32 int
33 p_log(...)
34 {
35  // log(+LogLevel, +LogString)
36 
37  fawkes::Logger *logger;
38  try {
40  } catch (fawkes::Exception &e) {
41  e.print_trace();
42  return EC_fail;
43  }
44 
45  EC_atom log_level;
46  if (EC_succeed != EC_arg(1).is_atom(&log_level)) {
47  printf("Could not obtain log level\n");
48  return EC_fail;
49  }
50 
52  if (0 == strcmp("ll_debug", log_level.name())) {
54  } else if (0 == strcmp("ll_info", log_level.name())) {
56  } else if (0 == strcmp("ll_warn", log_level.name())) {
58  } else if (0 == strcmp("ll_error", log_level.name())) {
60  } else {
61  printf("Unknown log level %s\n", log_level.name());
62  return EC_fail;
63  }
64 
65  char *log_string;
66  if (EC_succeed != EC_arg(2).is_string(&log_string)) {
67  printf("Could not get 2nd argument of log/2\n");
68  return EC_fail;
69  }
70 
71  logger->log(ll, "ECLiPSe CLP", log_string);
72 
73  return EC_succeed;
74 }
EclipseAgentThread::instance
static EclipseAgentThread * instance()
Get the EclipseAgentThread instance.
Definition: eclipse_thread.cpp:255
EclipseAgentThread::get_logger
fawkes::Logger * get_logger()
Get the logger.
Definition: eclipse_thread.cpp:246
fawkes::Logger::LL_DEBUG
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
fawkes::MultiLogger::log
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: multi.cpp:159
fawkes::Logger::LL_INFO
@ LL_INFO
informational output about normal procedures
Definition: logger.h:53
fawkes::Logger
Definition: logger.h:41
fawkes::Logger::LL_ERROR
@ LL_ERROR
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:57
fawkes::Exception::print_trace
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:601
fawkes::Logger::LogLevel
LogLevel
Log level.
Definition: logger.h:51
fawkes::Logger::LL_WARN
@ LL_WARN
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:54
fawkes::Exception
Definition: exception.h:41