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

ROSOUT_TOPIC =

topic name of rosout

'/rosout'

Instance Method Summary (collapse)

Constructor Details

- (Log) initialize(node, output = $stdout)

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



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.

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



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, 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
  if /in `(.*)'/ =~ function
    msg.function = $1
  else
    msg.function = ''
  end
  msg.line = line
  msg.topics = @node.get_published_topics
  @rosout.publish(msg)
  self
end