Class: Server::Log
- Inherits:
-
Object
- Object
- Server::Log
- Defined in:
- lib/server/log.rb
Instance Method Summary collapse
- #add(severity, msg) ⇒ Object
- #debug(msg) ⇒ Object
- #error(msg) ⇒ Object
- #fatal(msg) ⇒ Object
- #format_date(format = '%Y-%m-%d %H:%M:%S') ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(output_stream) ⇒ Log
constructor
A new instance of Log.
- #set_prompts ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize(output_stream) ⇒ Log
Returns a new instance of Log.
10 11 12 13 14 15 16 |
# File 'lib/server/log.rb', line 10 def initialize(output_stream) @instance = Logger.new(output_stream) format_date set_prompts return @instance end |
Instance Method Details
#add(severity, msg) ⇒ Object
64 65 66 |
# File 'lib/server/log.rb', line 64 def add(severity, msg) @instance.add(severity, msg) end |
#debug(msg) ⇒ Object
43 44 45 46 |
# File 'lib/server/log.rb', line 43 def debug(msg) text = @instance.debug(msg) puts "Debug text? #{text}" end |
#error(msg) ⇒ Object
56 57 58 |
# File 'lib/server/log.rb', line 56 def error(msg) @instance.error(msg) end |
#fatal(msg) ⇒ Object
60 61 62 |
# File 'lib/server/log.rb', line 60 def fatal(msg) @instance.fatal(msg) end |
#format_date(format = '%Y-%m-%d %H:%M:%S') ⇒ Object
18 19 20 |
# File 'lib/server/log.rb', line 18 def format_date(format = '%Y-%m-%d %H:%M:%S') @instance.datetime_format = format end |
#info(msg) ⇒ Object
48 49 50 |
# File 'lib/server/log.rb', line 48 def info(msg) @instance.info(msg) end |
#set_prompts ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/server/log.rb', line 22 def set_prompts @instance.formatter = proc do |severity, datetime, progname, msg| case severity.downcase when "debug" prompt = "☰ ".blue when "info" prompt = "i ".green when "warn" prompt = "⚑ ".magenta when "error" prompt = "✖ ".red when "fatal" prompt = ":( ".red else prompt = "✓ ".blue end ( ARGV.include? "-e" ) ? "#{prompt} #{datetime.strftime("%Y/%m/%d %H:%M:%S")} \n » #{msg.strip} \n\n" : "#{prompt} #{msg.strip} \n" end end |
#warn(msg) ⇒ Object
52 53 54 |
# File 'lib/server/log.rb', line 52 def warn(msg) @instance.warn(msg) end |