27 #include "../BuildConfig.h"
30 #ifdef TERRALIB_LOGGER_ENABLED
33 #include "Exception.h"
41 #include <boost/filesystem.hpp>
44 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
45 #include <log4cxx/basicconfigurator.h>
46 #include <log4cxx/consoleappender.h>
47 #include <log4cxx/logger.h>
48 #include <log4cxx/logmanager.h>
49 #include <log4cxx/patternlayout.h>
50 #include <log4cxx/propertyconfigurator.h>
51 #include <log4cxx/xml/domconfigurator.h>
54 void te::common::Logger::initialize(
const std::string& loggerName,
56 const std::string& fileName)
58 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
67 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggerName));
70 throw Exception(
TE_TR(
"It was not possible to initialize the logger!"));
74 log4cxx::xml::DOMConfigurator::configure(fileName);
78 log4cxx::PropertyConfigurator::configure(fileName);
82 throw Exception(
TE_TR(
"Invalid logger configuration type!"));
87 void te::common::Logger::initialize(
const std::string& loggerName)
89 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
92 log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggerName));
95 throw Exception(
TE_TR(
"It was not possible to initialize the the logger!"));
99 void te::common::Logger::finalize(
const std::string& loggerName)
101 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
102 if(loggerName.empty())
103 throw Exception(
TE_TR(
"The logger name is empty!"));
105 log4cxx::LoggerPtr logger = log4cxx::LogManager::exists(loggerName);
110 logger->removeAllAppenders();
114 void te::common::Logger::logFatal(
const char* logger,
const char* msg)
116 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
117 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
118 LOG4CXX_FATAL(lo, msg);
122 void te::common::Logger::logFatal(
const std::string& logger,
const std::string& msg)
124 logFatal(logger.c_str(), msg.c_str());
127 void te::common::Logger::logAssert(
const char* logger,
bool condition,
const char* msg)
129 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
130 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
131 LOG4CXX_ASSERT(lo, condition, msg);
135 void te::common::Logger::logError(
const char* logger,
const char* msg)
137 #if TE_USE_APACHE_LOG4CXX
138 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
139 LOG4CXX_ERROR(lo, msg);
143 void te::common::Logger::logWarning(
const char* logger,
const char* msg)
145 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
146 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
147 LOG4CXX_WARN(lo, msg);
151 void te::common::Logger::logInfo(
const char* logger,
const char* msg)
153 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
154 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
155 LOG4CXX_INFO(lo, msg);
159 void te::common::Logger::logInfo(
const std::string& logger,
const std::string& msg)
161 logInfo(logger.c_str(), msg.c_str());
164 void te::common::Logger::logDebug(
const char* logger,
const char* msg)
166 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
167 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
168 LOG4CXX_DEBUG(lo, msg);
172 void te::common::Logger::logTrace(
const char* logger,
const char* msg)
174 #ifdef TERRALIB_APACHE_LOG4CXX_ENABLED
175 log4cxx::LoggerPtr lo(log4cxx::Logger::getLogger(logger));
176 LOG4CXX_TRACE(lo, msg);
180 void te::common::Logger::logTrace(
const std::string& logger,
const std::string& msg)
182 logTrace(logger.c_str(), msg.c_str());
185 #endif // TERRALIB_LOGGER_ENABLED
#define TE_TR(message)
It marks a string in order to get translated.
LoggerConfigurationType
Each enumerated type tells TerraLib how the configuration is done for a logger.
This class is designed for dealing with multi-language text translation in TerraLib.
This class is designed to manage the log of information in TerraLib.