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
32int
33p_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}
static EclipseAgentThread * instance()
Get the EclipseAgentThread instance.
fawkes::Logger * get_logger()
Get the logger.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void print_trace() noexcept
Prints trace to stderr.
Definition: exception.cpp:601
Interface for logging.
Definition: logger.h:42
LogLevel
Log level.
Definition: logger.h:51
@ LL_INFO
informational output about normal procedures
Definition: logger.h:53
@ LL_WARN
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:54
@ LL_ERROR
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:57
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: multi.cpp:153