Class: Rango::Logger

  • Logger
    • Rango::Logger

Constructor Summary

public initialize(output = STDERR)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


10
11
12
13
# File 'lib/rango/loggers/logger.rb', line 10

def initialize(output = STDERR)
  super(output)
  self.setup
end

Public Visibility

Public Instance Method Summary

#debug(*args)

Logger methods can takes more arguments and they returns array with arguments NOTE: why we dup args each time? Because we colorize messages, but if logger method is used for handling requests, we just need to send noncolored messages as response.

#error(*args)
#exception(exception)
#fatal(*args)
#info(*args)
#inspect(*args)

Project.

#setup
#setup_format
#warn(*args)

Public Instance Method Details

debug

public debug(*args)

Logger methods can takes more arguments and they returns array with arguments NOTE: why we dup args each time? Because we colorize messages, but if logger method is used for handling requests, we just need to send noncolored messages as response.

Meta Tags

Parameters:

Since:

0.0.1

[View source]


36
37
38
39
40
# File 'lib/rango/loggers/logger.rb', line 36

def debug(*args)
  original = args.dup
  args.map { |arg| super(arg) }
  return original
end

error

public error(*args)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


57
58
59
60
61
# File 'lib/rango/loggers/logger.rb', line 57

def error(*args)
  original = args.dup
  args.map { |arg| super(arg) }
  return original
end

exception

public exception(exception)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


23
24
25
26
27
28
29
30
# File 'lib/rango/loggers/logger.rb', line 23

def exception(exception)
  self.error("#{exception.message} (#{exception.class})")
  exception.backtrace.each do |line|
    unless line.match(/thin|eventmachine/)
      STDERR.puts("- #{line.colorize.cyan}")
    end
  end
end

fatal

public fatal(*args)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


64
65
66
67
68
# File 'lib/rango/loggers/logger.rb', line 64

def fatal(*args)
  original = args.dup
  args.map { |arg| super(arg) }
  return original
end

info

public info(*args)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


43
44
45
46
47
# File 'lib/rango/loggers/logger.rb', line 43

def info(*args)
  original = args.dup
  args.map { |arg| super(arg) }
  return original
end

inspect

public inspect(*args)

Project.logger.inspect(@posts, item) Project.logger.inspect(“@post” => @post)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


73
74
75
76
77
78
79
80
81
82
# File 'lib/rango/loggers/logger.rb', line 73

def inspect(*args)
  if args.first.is_a?(Hash) && args.length.eql?(1)
    args.first.each do |name, value|
      self.debug("#{name}: #{value.inspect}")
    end
  else
    args = args.map { |arg| arg.inspect }
    self.debug(*args)
  end
end

setup

public setup

Meta Tags

Parameters:

Since:

0.0.1

[View source]


16
17
18
19
20
# File 'lib/rango/loggers/logger.rb', line 16

def setup
  self.level = ::Logger::DEBUG
  self.datetime_format = "%H:%M:%S"
  self.setup_format
end

setup_format

public setup_format

Meta Tags

Parameters:

Since:

0.0.1

[View source]


85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rango/loggers/logger.rb', line 85

def setup_format
  self.formatter = lambda do |severity, datetime, progname, msg|
    # logger.debug(object_to_inspect)
    msg = msg.inspect unless msg.is_a?(String)
    datetime = datetime.strftime("[%H:%M:%S]")
    case severity
    when "DEBUG" then "#{datetime} #{msg.colorize.yellow}\n"
    when "INFO"  then "#{datetime} #{msg.colorize.green}\n"
    when "WARN"  then "#{datetime} #{msg.colorize.yellow}\n"
    when "ERROR" then "#{datetime} #{msg.colorize.red}\n"
    when "FATAL" then "#{datetime} #{msg.colorize.red.bold}\n"
    end
  end
end

warn

public warn(*args)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


50
51
52
53
54
# File 'lib/rango/loggers/logger.rb', line 50

def warn(*args)
  original = args.dup
  args.map { |arg| super(arg) }
  return original
end