ogre_logging.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreLogManager.h>
31 #include <OgreLog.h>
32 
33 #include <ros/ros.h>
34 
37 
38 namespace rviz
39 {
40 class RosLogListener : public Ogre::LogListener
41 {
42 public:
43  RosLogListener() : min_lml(Ogre::LML_CRITICAL){};
44  ~RosLogListener() override
45  {
46  }
47 
48  void messageLogged(const Ogre::String& message,
49  Ogre::LogMessageLevel lml,
50  bool /*maskDebug*/,
51  const Ogre::String& /*logName*/,
52  bool& skipThisMessage) override
53  {
54  if (!skipThisMessage)
55  {
56  if (lml >= min_lml)
57  {
58  ROS_LOG((ros::console::levels::Level)(lml - 1), ROSCONSOLE_DEFAULT_NAME, "%s", message.c_str());
59  }
60  }
61  }
62  Ogre::LogMessageLevel min_lml;
63 };
64 
67 
70 {
72 }
73 
78 void OgreLogging::useLogFile(const QString& filename)
79 {
81  filename_ = filename;
82 }
83 
86 {
88 }
89 
96 {
97  static RosLogListener ll;
98  Ogre::LogManager* log_manager = Ogre::LogManager::getSingletonPtr();
99  if (log_manager == nullptr)
100  {
101  log_manager = new Ogre::LogManager();
102  }
103  Ogre::Log* l = log_manager->createLog(filename_.toStdString(), false, false, preference_ == NoLogging);
104  l->addListener(&ll);
105 
106  // Printing to standard out is what Ogre does if you don't do any LogManager calls.
107  if (preference_ == StandardOut)
108  {
109  ll.min_lml = Ogre::LML_NORMAL;
110  }
111 }
112 
113 } // end namespace rviz
rviz::RosLogListener::~RosLogListener
~RosLogListener() override
Definition: ogre_logging.cpp:44
Ogre
Definition: axes_display.h:35
version_check.h
ros.h
ogre_logging.h
rviz::OgreLogging::useLogFile
static void useLogFile(const QString &filename="Ogre.log")
Configure Ogre to write output to the given log file name. If file name is a relative path,...
Definition: ogre_logging.cpp:78
rviz::OgreLogging::configureLogging
static void configureLogging()
Configure the Ogre::LogManager to give the currently selected behavior. This must be called before Og...
Definition: ogre_logging.cpp:95
rviz::OgreLogging::NoLogging
@ NoLogging
Definition: ogre_logging.h:70
rviz::OgreLogging::preference_
static Preference preference_
Definition: ogre_logging.h:72
rviz::OgreLogging::filename_
static QString filename_
Definition: ogre_logging.h:73
rviz
Definition: add_display_dialog.cpp:54
rviz::RosLogListener::messageLogged
void messageLogged(const Ogre::String &message, Ogre::LogMessageLevel lml, bool, const Ogre::String &, bool &skipThisMessage) override
Definition: ogre_logging.cpp:48
ROS_LOG
#define ROS_LOG(level, name,...)
ros::console::levels::Level
Level
rviz::OgreLogging::Preference
Preference
Definition: ogre_logging.h:66
rviz::RosLogListener::min_lml
Ogre::LogMessageLevel min_lml
Definition: ogre_logging.cpp:62
rviz::OgreLogging::useRosLog
static void useRosLog()
Configure Ogre to write output to the ROS logger.
Definition: ogre_logging.cpp:69
ROSCONSOLE_DEFAULT_NAME
#define ROSCONSOLE_DEFAULT_NAME
rviz::OgreLogging::FileLogging
@ FileLogging
Definition: ogre_logging.h:69
rviz::OgreLogging::noLog
static void noLog()
Disable Ogre logging entirely. This is the default.
Definition: ogre_logging.cpp:85
rviz::RosLogListener::RosLogListener
RosLogListener()
Definition: ogre_logging.cpp:43
rviz::RosLogListener
Definition: ogre_logging.cpp:40
rviz::OgreLogging::StandardOut
@ StandardOut
Definition: ogre_logging.h:68


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02