ogre_logging.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <OgreLogManager.h>
00031 #include <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   // Printing to standard out is what Ogre does if you don't do any LogManager calls.
00111   if( preference_ == StandardOut )
00112   {
00113     ll.min_lml=Ogre::LML_NORMAL;
00114   }
00115 }
00116 
00117 } // end namespace rviz


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Jun 6 2019 18:02:15