example.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 ********************************************************************/
34 
35 #include "ros/console.h"
36 #include <log4cxx/logger.h>
37 
38 void print(ros::console::Level level, const std::string& s)
39 {
40  ROS_LOG(level, ROSCONSOLE_DEFAULT_NAME, "%s", s.c_str());
41 }
42 
43 int main(int /*argc*/, char** /*argv*/)
44 {
45  // This needs to happen before we start fooling around with logger levels. Otherwise the level we set may be overwritten by
46  // a configuration file
48 
49  log4cxx::LoggerPtr my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
50 
51  // Set the logger for this package to output all statements
53 
54  // All these should print
55  ROS_DEBUG("This is a debug statement, and should print");
56  ROS_INFO("This is an info statement, and should print");
57  ROS_WARN("This is a warn statement, and should print");
58  ROS_ERROR("This is an error statement, and should print");
59  ROS_FATAL("This is a fatal statement, and should print");
60 
61  // This should also print
62  print(ros::console::levels::Debug, "Hello, this should print");
63 
65  // This will STILL print, because the logger's enabled state has been cached
66  print(ros::console::levels::Debug, "Hello, this will also print");
67 
68  // Calling notifyLoggerLevelsChanged() will force a reevaluation of which logging statements are enabled
70  // Which will cause this to not print
71  print(ros::console::levels::Debug, "Hello, this will NOT print");
72 
73  log4cxx::LoggerPtr ros_logger = log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME);
74 
77  ROS_DEBUG("This will still print, because the child logger's level overrides its ancestor loggers' levels");
78 
79  log4cxx::LoggerPtr test_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME".test");
81  ROS_INFO_NAMED("test", "This will not print, because the ros.rosconsole.test logger has been set to Error verbosity");
83  ROS_INFO_NAMED("test", "Now everything sent to the ros.rosconsole.test logger will be printed (including this)");
84 
85  return 0;
86 }
print
void print(ros::console::Level level, const std::string &s)
Definition: example.cpp:38
ros::console::levels::Error
@ Error
Definition: console_backend.h:58
console.h
ROSCONSOLE_AUTOINIT
#define ROSCONSOLE_AUTOINIT
Initializes the rosconsole library. Usually unnecessary to call directly.
Definition: console.h:327
ROSCONSOLE_ROOT_LOGGER_NAME
#define ROSCONSOLE_ROOT_LOGGER_NAME
Definition: console.h:302
ros::console::levels::Debug
@ Debug
Definition: console_backend.h:55
ROS_INFO_NAMED
#define ROS_INFO_NAMED(name,...)
Definition: macros_generated.h:112
ROS_DEBUG
#define ROS_DEBUG(...)
Definition: macros_generated.h:58
ROS_WARN
#define ROS_WARN(...)
Definition: macros_generated.h:162
ROS_LOG
#define ROS_LOG(level, name,...)
Log to a given named logger at a given verbosity level, with printf-style formatting.
Definition: console.h:575
ros::console::levels::Level
Level
Definition: console_backend.h:53
ROS_FATAL
#define ROS_FATAL(...)
Definition: macros_generated.h:266
ros::console::notifyLoggerLevelsChanged
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
Definition: rosconsole.cpp:732
ros::console::impl::g_level_lookup
log4cxx::LevelPtr g_level_lookup[levels::Count]
Definition: rosconsole_log4cxx.cpp:69
ROS_ERROR
#define ROS_ERROR(...)
Definition: macros_generated.h:214
main
int main(int, char **)
Definition: example.cpp:43
ROSCONSOLE_DEFAULT_NAME
#define ROSCONSOLE_DEFAULT_NAME
Definition: console.h:304
ROS_INFO
#define ROS_INFO(...)
Definition: macros_generated.h:110


rosconsole
Author(s): Josh Faust
autogenerated on Wed Mar 2 2022 00:53:52