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 #include <cstdio>
00033 
00034 int
00035 p_log()
00036 {
00037   // log(+LogLevel, +LogString)
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 }

Generated on Tue Feb 22 13:31:29 2011 for Fawkes API by  doxygen 1.4.7