Class: RubyExts::Logger
Instance Method Summary collapse
-
#debug(*args) ⇒ Object
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) ⇒ Object
- #exception(exception) ⇒ Object
- #fatal(*args) ⇒ Object
- #info(*args) ⇒ Object
-
#initialize(output = STDERR) ⇒ Logger
constructor
A new instance of Logger.
-
#inspect(*args) ⇒ Object
Project.logger.inspect(@posts, item) Project.logger.inspect(“@post” => @post).
- #setup ⇒ Object
- #setup_format ⇒ Object
- #warn(*args) ⇒ Object
Constructor Details
#initialize(output = STDERR) ⇒ Logger
Returns a new instance of Logger.
11 12 13 14 |
# File 'lib/rubyexts/logger.rb', line 11 def initialize(output = STDERR) super(output) self.setup end |
Instance Method Details
#debug(*args) ⇒ Object
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.
37 38 39 40 41 |
# File 'lib/rubyexts/logger.rb', line 37 def debug(*args) original = args.dup args.map { |arg| super(arg) } return original end |
#error(*args) ⇒ Object
58 59 60 61 62 |
# File 'lib/rubyexts/logger.rb', line 58 def error(*args) original = args.dup args.map { |arg| super(arg) } return original end |
#exception(exception) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rubyexts/logger.rb', line 24 def exception(exception) self.error("#{exception.} (#{exception.class})") exception.backtrace.each do |line| unless line.match(/thin|eventmachine/) STDERR.puts("- #{line.colorize.cyan}") end end end |
#fatal(*args) ⇒ Object
65 66 67 68 69 |
# File 'lib/rubyexts/logger.rb', line 65 def fatal(*args) original = args.dup args.map { |arg| super(arg) } return original end |
#info(*args) ⇒ Object
44 45 46 47 48 |
# File 'lib/rubyexts/logger.rb', line 44 def info(*args) original = args.dup args.map { |arg| super(arg) } return original end |
#inspect(*args) ⇒ Object
Project.logger.inspect(@posts, item) Project.logger.inspect(“@post” => @post)
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubyexts/logger.rb', line 74 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 ⇒ Object
17 18 19 20 21 |
# File 'lib/rubyexts/logger.rb', line 17 def setup self.level = ::Logger::DEBUG self.datetime_format = "%H:%M:%S" self.setup_format end |
#setup_format ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubyexts/logger.rb', line 86 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(*args) ⇒ Object
51 52 53 54 55 |
# File 'lib/rubyexts/logger.rb', line 51 def warn(*args) original = args.dup args.map { |arg| super(arg) } return original end |