Class: ROS::LocalLogger

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

Overview

Logger for local output

output with color escape sequence

Instance Method Summary (collapse)

Constructor Details

- (LocalLogger) initialize(io)

make local logger with color

Parameters:

  • io (IO)

    IO object for output



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

def initialize(io)
  @logger = Logger.new(io)
  # add color escape sequence
  @logger.formatter = proc {|severity, datetime, progname, msg|
    header = ''
    footer = ''
    if severity == 'ERROR' or severity == 'FATAL' 
      header = "\e[31m"
      footer = "\e[0m"
    elsif severity == 'WARN'
      header = "\e[33m"
      footer = "\e[0m"
    end
    header + "[#{severity}] #{msg}" + footer + "\n"
  }
end

Instance Method Details

- (Object) log(severity, message, progname)

output to logger with unixtime

Parameters:

  • severity (String)

    log level

  • message (String)

    message for output

  • progname (String)

    name of this program (node name)



49
50
51
# File 'lib/ros/log.rb', line 49

def log(severity, message, progname)
  return @logger.log(severity, "[Walltime: #{::Time.now.to_f}] " + message, progname)
end