fawkes_logger.cpp

00001
00002 /***************************************************************************
00003  *  fawkes_logger.cpp - External predicates that allow the usage of the Logger
00004  *
00005  *  Created: Wed Jul 22 11:25:21 2009
00006  *  Copyright  2009  Daniel Beck
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
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   // log(+LogLevel, +LogString)
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 }