Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <OGRE/OgreLogManager.h>
00031 #include <OGRE/OgreLog.h>
00032
00033 #include <ros/ros.h>
00034
00035 #include "rviz/ogre_helpers/ogre_logging.h"
00036
00037 namespace rviz
00038 {
00039
00040 class RosLogListener: public Ogre::LogListener
00041 {
00042 public:
00043 RosLogListener(): min_lml(Ogre::LML_CRITICAL) {};
00044 virtual ~RosLogListener() {}
00045
00046 #if OGRE_VERSION >= ((1 << 16) | (8 << 8))
00047 virtual void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool& skipThisMessage )
00048 {
00049 if ( !skipThisMessage )
00050 {
00051 if ( lml >= min_lml )
00052 {
00053 ROS_LOG((ros::console::levels::Level)(lml-1), ROSCONSOLE_DEFAULT_NAME, "%s", message.c_str() );
00054 }
00055 }
00056 }
00057 #else
00058 virtual void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName )
00059 {
00060 if ( lml >= min_lml )
00061 {
00062 ROS_LOG((ros::console::levels::Level)(lml-1), ROSCONSOLE_DEFAULT_NAME, "%s", message.c_str() );
00063 }
00064 }
00065 #endif
00066 Ogre::LogMessageLevel min_lml;
00067 };
00068
00069 OgreLogging::Preference OgreLogging::preference_ = OgreLogging::NoLogging;
00070 QString OgreLogging::filename_;
00071
00073 void OgreLogging::useRosLog()
00074 {
00075 preference_ = StandardOut;
00076 }
00077
00082 void OgreLogging::useLogFile( const QString& filename )
00083 {
00084 preference_ = FileLogging;
00085 filename_ = filename;
00086 }
00087
00089 void OgreLogging::noLog()
00090 {
00091 preference_ = NoLogging;
00092 }
00093
00099 void OgreLogging::configureLogging()
00100 {
00101 static RosLogListener ll;
00102 Ogre::LogManager* log_manager = Ogre::LogManager::getSingletonPtr();
00103 if( log_manager == NULL )
00104 {
00105 log_manager = new Ogre::LogManager();
00106 }
00107 Ogre::Log* l = log_manager->createLog( filename_.toStdString(), false, false, preference_==NoLogging );
00108 l->addListener( &ll );
00109
00110
00111 if( preference_ == StandardOut )
00112 {
00113 ll.min_lml=Ogre::LML_NORMAL;
00114 }
00115 }
00116
00117 }