32 #include "Exception.h"
40 #include <boost/filesystem.hpp>
43 #if TE_USE_APACHE_LOG4CXX
44 #include <log4cxx/basicconfigurator.h>
45 #include <log4cxx/consoleappender.h>
46 #include <log4cxx/logger.h>
47 #include <log4cxx/logmanager.h>
48 #include <log4cxx/patternlayout.h>
49 #include <log4cxx/propertyconfigurator.h>
50 #include <log4cxx/xml/domconfigurator.h>
53 std::string te::common::Logger::getDefaultConfigFile()
60 char* e = getenv(TE_DIR_ENVIRONMENT_VARIABLE);
64 boost::filesystem::path p(e);
67 if(boost::filesystem::exists(p))
75 void te::common::Logger::initialize(
const std::string& loggerName,
77 const std::string& fileName)
79 #if TE_USE_APACHE_LOG4CXX
88 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggerName));
91 throw Exception(
TR_COMMON(
"It was not possible to initialize the logger!"));
95 log4cxx::xml::DOMConfigurator::configure(fileName);
99 log4cxx::PropertyConfigurator::configure(fileName);
103 throw Exception(
TR_COMMON(
"Invalid logger configuration type!"));
108 void te::common::Logger::initialize(
const std::string& loggerName)
110 #if TE_USE_APACHE_LOG4CXX
111 finalize(loggerName);
113 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggerName));
116 throw Exception(
TR_COMMON(
"It was not possible to initialize the the logger!"));
120 void te::common::Logger::finalize(
const std::string& loggerName)
122 #if TE_USE_APACHE_LOG4CXX
123 if(loggerName.empty())
124 throw Exception(
TR_COMMON(
"The logger name is empty!"));
126 log4cxx::LoggerPtr logger = log4cxx::LogManager::exists(loggerName);
131 logger->removeAllAppenders();
135 void te::common::Logger::logFatal(
const char* logger,
const char* msg)
137 #if TE_USE_APACHE_LOG4CXX
138 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
139 LOG4CXX_FATAL(lo, msg);
143 void te::common::Logger::logFatal(
const std::string& logger,
const std::string& msg)
145 logFatal(logger.c_str(), msg.c_str());
148 void te::common::Logger::logAssert(
const char* logger,
bool condition,
const char* msg)
150 #if TE_USE_APACHE_LOG4CXX
151 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
152 LOG4CXX_ASSERT(lo, condition, msg);
156 void te::common::Logger::logError(
const char* logger,
const char* msg)
158 #if TE_USE_APACHE_LOG4CXX
159 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
160 LOG4CXX_ERROR(lo, msg);
164 void te::common::Logger::logWarning(
const char* logger,
const char* msg)
166 #if TE_USE_APACHE_LOG4CXX
167 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
168 LOG4CXX_WARN(lo, msg);
172 void te::common::Logger::logInfo(
const char* logger,
const char* msg)
174 #if TE_USE_APACHE_LOG4CXX
175 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
176 LOG4CXX_INFO(lo, msg);
180 void te::common::Logger::logInfo(
const std::string& logger,
const std::string& msg)
182 logInfo(logger.c_str(), msg.c_str());
185 void te::common::Logger::logDebug(
const char* logger,
const char* msg)
187 #if TE_USE_APACHE_LOG4CXX
188 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
189 LOG4CXX_DEBUG(lo, msg);
193 void te::common::Logger::logTrace(
const char* logger,
const char* msg)
195 #if TE_USE_APACHE_LOG4CXX
196 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
197 LOG4CXX_TRACE(lo, msg);
201 void te::common::Logger::logTrace(
const std::string& logger,
const std::string& msg)
203 logTrace(logger.c_str(), msg.c_str());
206 #endif // TE_LOGGER_ENABLED
LoggerConfigurationType
Each enumerated type tells TerraLib how the configuration is done for a logger.
#define TE_LOGGER_DEFAULT_CONFIGURATION_FILE
#define TR_COMMON(message)
It marks a string in order to get translated. This is the mark used in the Common module of TerraLib...
This class is designed to manage the log of information in TerraLib.
This class is designed for dealing with multi-language text translation in TerraLib.