Class: ROS::Log
- Inherits:
-
Object
- Object
- ROS::Log
- Defined in:
- lib/ros/log.rb
Overview
Logging class for ROS
This class enable double logging: ROS Logging system and ruby log.
Constant Summary
- ROSOUT_TOPIC =
topic name of rosout
'/rosout'
Instance Method Summary (collapse)
-
- (Log) initialize(node, output = $stdout)
constructor
start publishing /rosout and make a ruby logger instance for local output.
-
- (Log) log(severity, message, file = '', function = '', line = 0)
outputs log messages with level and informations which rosout needs.
Constructor Details
- (Log) initialize(node, output = $stdout)
start publishing /rosout and make a ruby logger instance for local output
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ros/log.rb', line 66 def initialize(node, output=$stdout) @node = node @rosout = @node.advertise(ROSOUT_TOPIC, Rosgraph_msgs::Log, :no_resolve=>true) @ruby_dict = {'FATAL'=>Logger::FATAL, 'ERROR'=>Logger::ERROR, 'WARN'=>Logger::WARN, 'INFO'=>Logger::INFO, 'DEBUG'=>Logger::DEBUG} @msg_dict = {'FATAL'=>::Rosgraph_msgs::Log::FATAL, 'ERROR'=>::Rosgraph_msgs::Log::ERROR, 'WARN'=>::Rosgraph_msgs::Log::WARN, 'INFO'=>::Rosgraph_msgs::Log::INFO, 'DEBUG'=>::Rosgraph_msgs::Log::DEBUG} @local_logger = LocalLogger.new(output) end |
Instance Method Details
- (Log) log(severity, message, file = '', function = '', line = 0)
outputs log messages with level and informations which rosout needs.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ros/log.rb', line 92 def log(severity, , file='', function='', line=0) @local_logger.log(@ruby_dict[severity], , @node.node_name) msg = Rosgraph_msgs::Log.new msg.msg = msg.header.stamp = ::ROS::Time.now msg.header.frame_id = 'rosout' msg.level = @msg_dict[severity] msg.name = @node.node_name msg.file = file if /in `(.*)'/ =~ function msg.function = $1 else msg.function = '' end msg.line = line msg.topics = @node.get_published_topics @rosout.publish(msg) self end |