Module: Yarn::Logging

Included in:
AbstractHandler, DirectoryLister, Server
Defined in:
lib/yarn/logging.rb

Overview

Enables logging messages to $output.

Instance Method Summary collapse

Instance Method Details

#debug(msg = nil) ⇒ Object

Appends DEBUG to a log message. Doesnt do anything if debugging is disabled.



22
23
24
# File 'lib/yarn/logging.rb', line 22

def debug(msg=nil)
  log "DEBUG: #{msg}" if $debug
end

#log(msg) ⇒ Object

Logs a message to $output. Doesnt do anything unless logging or debugging is enabled.



9
10
11
12
13
14
15
16
17
18
# File 'lib/yarn/logging.rb', line 9

def log(msg)
  return nil unless $log
  if msg.respond_to?(:each)
    msg.each do |line|
      output.puts "#{timestamp} #{line}"
    end
  else
    output.puts "#{timestamp} #{msg}"
  end
end

#outputObject

Proxy for the output variable.



27
28
29
30
# File 'lib/yarn/logging.rb', line 27

def output
  out ||= $output || $stdout
  out
end

#timestampObject

Returns a formattet timestamp.



33
34
35
36
# File 'lib/yarn/logging.rb', line 33

def timestamp
  current_time = DateTime.now
  "#{current_time.strftime("%d/%m/%y %H:%M:%S")} -"
end