fawkes_logger.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "fawkes_logger.h"
00024 #include <plugins/readylogagent/eclipse_thread.h>
00025
00026 #include <utils/logging/logger.h>
00027 #include <core/exception.h>
00028
00029 #include <eclipseclass.h>
00030
00031 #include <cstring>
00032
00033 int
00034 p_log()
00035 {
00036
00037
00038 fawkes::Logger* logger;
00039 try
00040 {
00041 logger = EclipseAgentThread::instance()->get_logger();
00042 }
00043 catch ( fawkes::Exception& e )
00044 {
00045 e.print_trace();
00046 return EC_fail;
00047 }
00048
00049 EC_atom log_level;
00050 if ( EC_succeed != EC_arg( 1 ).is_atom( &log_level ) )
00051 {
00052 printf( "Could not obtain log level\n" );
00053 return EC_fail;
00054 }
00055
00056 fawkes::Logger::LogLevel ll;
00057 if ( 0 == strcmp( "ll_debug", log_level.name() ) )
00058 {
00059 ll = fawkes::Logger::LL_DEBUG;
00060 }
00061 else if ( 0 == strcmp( "ll_info", log_level.name() ) )
00062 {
00063 ll = fawkes::Logger::LL_INFO;
00064 }
00065 else if ( 0 == strcmp( "ll_warn", log_level.name() ) )
00066 {
00067 ll = fawkes::Logger::LL_WARN;
00068 }
00069 else if ( 0 == strcmp( "ll_error", log_level.name() ) )
00070 {
00071 ll = fawkes::Logger::LL_ERROR;
00072 }
00073 else
00074 {
00075 printf( "Unknown log level %s\n", log_level.name() );
00076 return EC_fail;
00077 }
00078
00079 char* log_string;
00080 if ( EC_succeed != EC_arg( 2 ).is_string( &log_string ) )
00081 {
00082 printf( "Could not get 2nd argument of log/2\n" );
00083 return EC_fail;
00084 }
00085
00086 logger->log( ll, "ReadylogAgent", log_string );
00087
00088 return EC_succeed;
00089 }