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 #include <plugins/eclipse-clp/eclipse_thread.h>
25 
26 #include <logging/logger.h>
27 #include <core/exception.h>
28 
29 #include <eclipseclass.h>
30 //#include "../eclipse_class_include.h"
31 
32 #include <cstring>
33 #include <cstdio>
34 
35 int
36 p_log(...)
37 {
38  // log(+LogLevel, +LogString)
39 
40  fawkes::Logger* logger;
41  try
42  {
44  }
45  catch ( fawkes::Exception& e )
46  {
47  e.print_trace();
48  return EC_fail;
49  }
50 
51  EC_atom log_level;
52  if ( EC_succeed != EC_arg( 1 ).is_atom( &log_level ) )
53  {
54  printf( "Could not obtain log level\n" );
55  return EC_fail;
56  }
57 
59  if ( 0 == strcmp( "ll_debug", log_level.name() ) )
60  {
62  }
63  else if ( 0 == strcmp( "ll_info", log_level.name() ) )
64  {
66  }
67  else if ( 0 == strcmp( "ll_warn", log_level.name() ) )
68  {
70  }
71  else if ( 0 == strcmp( "ll_error", log_level.name() ) )
72  {
74  }
75  else
76  {
77  printf( "Unknown log level %s\n", log_level.name() );
78  return EC_fail;
79  }
80 
81  char* log_string;
82  if ( EC_succeed != EC_arg( 2 ).is_string( &log_string ) )
83  {
84  printf( "Could not get 2nd argument of log/2\n" );
85  return EC_fail;
86  }
87 
88  logger->log( ll, "ECLiPSe CLP", log_string );
89 
90  return EC_succeed;
91 }
LogLevel
Log level.
Definition: logger.h:45
informational output about normal procedures
Definition: logger.h:47
fawkes::Logger * get_logger()
Get the logger.
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:48
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:51
static EclipseAgentThread * instance()
Get the EclipseAgentThread instance.
Base class for exceptions in Fawkes.
Definition: exception.h:36
debug output, relevant only when tracking down problems
Definition: logger.h:46
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:315
Interface for logging.
Definition: logger.h:34