|
solarpowerlog trunk
|
00001 /* ---------------------------------------------------------------------------- 00002 solarpowerlog 00003 Copyright (C) 2009 Tobias Frost 00004 00005 This file is part of solarpowerlog. 00006 00007 Solarpowerlog is free software; However, it is dual-licenced 00008 as described in the file "COPYING". 00009 00010 For this file (ILogger.cpp), the license terms are: 00011 00012 You can redistribute it and/or modify it under the terms of the GNU 00013 General Public License as published by the Free Software Foundation; either 00014 version 3 of the License, or (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, but 00017 WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public 00022 License along with this proramm; if not, see 00023 <http://www.gnu.org/licenses/>. 00024 ---------------------------------------------------------------------------- 00025 */ 00026 00033 #include "config.h" 00034 00035 #include "configuration/ILogger.h" 00036 00037 #ifdef HAVE_LIBLOG4CXX 00038 00039 #include "configuration/CConfigHelper.h" 00040 #include <iostream> 00041 00042 using namespace std; 00043 00044 00049 ILogger::ILogger() 00050 { 00051 // if not overridden by setup, always log to the root logger. 00052 loggerptr_ = log4cxx::Logger::getRootLogger(); 00053 currentloggerlevel_ = loggerptr_->getLevel()->toInt(); 00054 } 00055 00071 void ILogger::Setup( const std::string & parent, 00072 const std::string & specialization ) 00073 { 00074 loggername_ = parent + "." + specialization; 00075 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggername_)); 00076 log4cxx::LevelPtr ptr=logger->getEffectiveLevel(); 00077 currentloggerlevel_ = ptr->toInt(); 00078 loggerptr_ = logger; 00079 } 00080 00081 00101 void ILogger::Setup( const string & name, const string & configuration, 00102 const string& section ) 00103 { 00104 string level; 00105 config_ = configuration; 00106 00107 loggername_ = section + "." + name; 00108 00109 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggername_)); 00110 loggerptr_ = logger; 00111 00112 // check if the logger has magically already a level. 00113 // if so, it must be from XML. 00114 log4cxx::LevelPtr ptr=logger->getLevel(); 00115 if (!ptr) { 00116 00117 CConfigHelper global("application"); 00118 global.GetConfig("dbglevel", level, (std::string) "ERROR"); 00119 00120 CConfigHelper hlp(configuration); 00121 hlp.GetConfig("dbglevel", level); 00122 00123 logger->setLevel(log4cxx::Level::toLevel(level)); 00124 } 00125 00126 currentloggerlevel_ = logger->getLevel()->toInt(); 00127 } 00128 00129 ILogger::~ILogger() 00130 { 00131 // TODO Auto-generated destructor stub 00132 } 00133 00134 #endif