32 #if defined(__APPLE__) && defined(__GNUC__) && defined(__llvm__) && !defined(__clang__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) 33 #error This code is known to provoke a compiler crash with llvm-gcc 4.2. You will have better luck with clang++. See code.ros.org/trac/ros/ticket/3626 39 #include "log4cxx/appenderskeleton.h" 40 #include "log4cxx/spi/loggingevent.h" 41 #include "log4cxx/level.h" 42 #include "log4cxx/propertyconfigurator.h" 45 #include "log4cxx/helpers/transcoder.h" 48 #include <boost/thread.hpp> 49 #include <boost/shared_array.hpp> 50 #include <boost/regex.hpp> 68 log4cxx::Level::getDebug(),
69 log4cxx::Level::getInfo(),
70 log4cxx::Level::getWarn(),
71 log4cxx::Level::getError(),
72 log4cxx::Level::getFatal(),
84 virtual void append(
const log4cxx::spi::LoggingEventPtr& event,
85 log4cxx::helpers::Pool&)
88 if (event->getLevel() == log4cxx::Level::getDebug())
92 else if (event->getLevel() == log4cxx::Level::getInfo())
96 else if (event->getLevel() == log4cxx::Level::getWarn())
100 else if (event->getLevel() == log4cxx::Level::getError())
104 else if (event->getLevel() == log4cxx::Level::getFatal())
109 LOG4CXX_ENCODE_CHAR(tmpstr, event->getMessage());
110 std::string msg = tmpstr
112 std::string msg =
event->getMessage();
114 const log4cxx::spi::LocationInfo& location_info =
event->getLocationInformation();
115 ::ros::console::backend::print(event.operator->(), level, msg.c_str(), location_info.getFileName(), location_info.getMethodName().c_str(), location_info.getLineNumber());
131 ros_logger->setLevel(log4cxx::Level::getInfo());
133 log4cxx::LoggerPtr roscpp_superdebug = log4cxx::Logger::getLogger(
"ros.roscpp.superdebug");
134 roscpp_superdebug->setLevel(log4cxx::Level::getWarn());
137 char* ros_root_cstr = NULL;
139 _dupenv_s(&ros_root_cstr, NULL,
"ROS_ROOT");
141 ros_root_cstr = getenv(
"ROS_ROOT");
145 std::string config_file = std::string(ros_root_cstr) +
"/config/rosconsole.config";
146 FILE* config_file_ptr = fopen( config_file.c_str(),
"r" );
147 if( config_file_ptr )
149 fclose( config_file_ptr );
150 log4cxx::PropertyConfigurator::configure(config_file);
153 char* config_file_cstr = NULL;
155 _dupenv_s(&config_file_cstr, NULL,
"ROSCONSOLE_CONFIG_FILE");
157 config_file_cstr = getenv(
"ROSCONSOLE_CONFIG_FILE");
159 if ( config_file_cstr )
161 std::string config_file = config_file_cstr;
162 log4cxx::PropertyConfigurator::configure(config_file);
168 if ( ros_root_cstr != NULL ) {
171 if ( config_file_cstr != NULL ) {
172 free(config_file_cstr);
174 if ( format_string != NULL ) {
182 void print(
void* handle, ::
ros::console::Level level,
const char* str,
const char* file,
const char*
function,
int line)
184 log4cxx::Logger* logger = (log4cxx::Logger*)handle;
187 logger->forcedLog(g_level_lookup[level], str, log4cxx::spi::LocationInfo(file,
function, line));
189 catch (std::exception& e)
191 fprintf(stderr,
"Caught exception while logging: [%s]\n", e.what());
197 log4cxx::Logger* logger = (log4cxx::Logger*)handle;
198 return logger->isEnabledFor(g_level_lookup[level]);
203 return log4cxx::Logger::getLogger(name);
206 std::string
getName(
void* handle)
208 const log4cxx::spi::LoggingEvent*
event = (
const log4cxx::spi::LoggingEvent*)handle;
210 LOG4CXX_ENCODE_CHAR(tmpstr, event->getLoggerName());
213 return event->getLoggerName();
217 bool get_loggers(std::map<std::string, levels::Level>& loggers)
221 log4cxx::LoggerList current_loggers = repo->getCurrentLoggers();
222 log4cxx::LoggerList::iterator it = current_loggers.begin();
223 log4cxx::LoggerList::iterator end = current_loggers.end();
224 for (; it != end; ++it)
228 LOG4CXX_ENCODE_CHAR(name, (*it)->getName());
230 name = (*it)->getName();
233 const log4cxx::LevelPtr& log4cxx_level = (*it)->getEffectiveLevel();
235 if (log4cxx_level == log4cxx::Level::getDebug())
239 else if (log4cxx_level == log4cxx::Level::getInfo())
243 else if (log4cxx_level == log4cxx::Level::getWarn())
247 else if (log4cxx_level == log4cxx::Level::getError())
251 else if (log4cxx_level == log4cxx::Level::getFatal())
259 loggers[name] = level;
267 log4cxx::LevelPtr log4cxx_level;
270 log4cxx_level = log4cxx::Level::getDebug();
274 log4cxx_level = log4cxx::Level::getInfo();
278 log4cxx_level = log4cxx::Level::getWarn();
282 log4cxx_level = log4cxx::Level::getError();
286 log4cxx_level = log4cxx::Level::getFatal();
293 log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(name);
294 logger->setLevel(log4cxx_level);
306 virtual void append(
const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool)
310 if (event->getLevel() == log4cxx::Level::getFatal())
314 else if (event->getLevel() == log4cxx::Level::getError())
318 else if (event->getLevel() == log4cxx::Level::getWarn())
322 else if (event->getLevel() == log4cxx::Level::getInfo())
326 else if (event->getLevel() == log4cxx::Level::getDebug())
336 LOG4CXX_ENCODE_CHAR(tmpstr, event->getMessage());
337 std::string msg = tmpstr
339 std::string msg =
event->getMessage();
342 const log4cxx::spi::LocationInfo& info =
event->getLocationInformation();
343 appender_->log(level, msg.c_str(), info.getFileName(), info.getMethodName().c_str(), info.getLineNumber());
357 logger->addAppender(g_log4cxx_appender);
363 logger->removeAppender(g_log4cxx_appender);
364 g_log4cxx_appender = 0;
370 log4cxx::Logger::getRootLogger()->getLoggerRepository()->shutdown();
log4cxx::LevelPtr g_level_lookup[levels::Count]
void print(void *handle,::ros::console::Level level, const char *str, const char *file, const char *function, int line)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
virtual void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &)
std::string getName(void *handle)
virtual bool requiresLayout() const
ros::console::LogAppender * appender_
#define ROSCONSOLE_ROOT_LOGGER_NAME
void register_appender(LogAppender *appender)
bool get_loggers(std::map< std::string, levels::Level > &loggers)
bool set_logger_level(const std::string &name, levels::Level level)
virtual void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &pool)
Log4cxxAppender(ros::console::LogAppender *appender)
bool isEnabledFor(void *handle,::ros::console::Level level)
Log4cxxAppender * g_log4cxx_appender
void * getHandle(const std::string &name)
virtual bool requiresLayout() const
~ROSConsoleStdioAppender()
void print(ros::console::Level level, const std::string &s)