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 #include <cstdio>
00033
00034 int
00035 p_log()
00036 {
00037
00038
00039 fawkes::Logger* logger;
00040 try
00041 {
00042 logger = EclipseAgentThread::instance()->get_logger();
00043 }
00044 catch ( fawkes::Exception& e )
00045 {
00046 e.print_trace();
00047 return EC_fail;
00048 }
00049
00050 EC_atom log_level;
00051 if ( EC_succeed != EC_arg( 1 ).is_atom( &log_level ) )
00052 {
00053 printf( "Could not obtain log level\n" );
00054 return EC_fail;
00055 }
00056
00057 fawkes::Logger::LogLevel ll;
00058 if ( 0 == strcmp( "ll_debug", log_level.name() ) )
00059 {
00060 ll = fawkes::Logger::LL_DEBUG;
00061 }
00062 else if ( 0 == strcmp( "ll_info", log_level.name() ) )
00063 {
00064 ll = fawkes::Logger::LL_INFO;
00065 }
00066 else if ( 0 == strcmp( "ll_warn", log_level.name() ) )
00067 {
00068 ll = fawkes::Logger::LL_WARN;
00069 }
00070 else if ( 0 == strcmp( "ll_error", log_level.name() ) )
00071 {
00072 ll = fawkes::Logger::LL_ERROR;
00073 }
00074 else
00075 {
00076 printf( "Unknown log level %s\n", log_level.name() );
00077 return EC_fail;
00078 }
00079
00080 char* log_string;
00081 if ( EC_succeed != EC_arg( 2 ).is_string( &log_string ) )
00082 {
00083 printf( "Could not get 2nd argument of log/2\n" );
00084 return EC_fail;
00085 }
00086
00087 logger->log( ll, "ReadylogAgent", log_string );
00088
00089 return EC_succeed;
00090 }