Class: ROS::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/ros/log.rb

Overview

Logging class for ROS

This class enable double logging: ROS Logging system and ruby log.

Constant Summary collapse

ROSOUT_TOPIC =

topic name of rosout

'/rosout'

Instance Method Summary collapse

Constructor Details

#initialize(node, output = $stdout) ⇒ Log

start publishing /rosout and make a ruby logger instance for local output

Parameters:

  • node (Node)

    Node instance

  • output (IO) (defaults to: $stdout)

    local output. $stdout is default



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ros/log.rb', line 30

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 = Logger.new(output)
end

Instance Method Details

#log(severity, message, file = '', function = '', line = 0) ⇒ Log

outputs log messages with level and informations which rosout needs.

Parameters:

  • severity (String)

    log level: one of ‘DEBUG’, ‘INFO’, ‘WARN’, ‘ERROR’, ‘FATAL’

  • message (String)

    your message

  • file (String) (defaults to: '')

    file name in which called this method

  • function (String) (defaults to: '')

    function name in which called this method

  • line (Integer) (defaults to: 0)

    line number in which called this method

Returns:

  • (Log)

    self



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ros/log.rb', line 56

def log(severity, message, file='', function='', line=0)
  @local_logger.log(@ruby_dict[severity], message, @node.node_name)
  msg = Rosgraph_msgs::Log.new
  msg.msg = message
  msg.header.stamp = ::ROS::Time.now
  msg.header.frame_id = 'rosout'
  msg.level = @msg_dict[severity]
  msg.name = @node.node_name
  msg.file = file
  msg.function = function
  msg.line = line
  msg.topics = @node.get_published_topics
  @rosout.publish(msg)
  self
end