Module: Quandl::Command::Task::Logging
- Extended by:
- ActiveSupport::Concern
- Included in:
- Quandl::Command::Task
- Defined in:
- lib/quandl/command/task/logging.rb
Instance Method Summary collapse
- #configure_logger ⇒ Object
- #debug(*args) ⇒ Object
- #error(*args) ⇒ Object
- #fatal(*args) ⇒ Object
- #info(*args) ⇒ Object
- #initialize_logger(path) ⇒ Object
- #log_request_time ⇒ Object
- #logger ⇒ Object
- #start_request_timer ⇒ Object
- #stderr_logger ⇒ Object
- #summarize(item) ⇒ Object
- #summarize_hash(item) ⇒ Object
- #table(*args) ⇒ Object
Instance Method Details
#configure_logger ⇒ Object
22 23 24 25 |
# File 'lib/quandl/command/task/logging.rb', line 22 def configure_logger @stderr_logger = initialize_logger(config.stderr) if config.stderr.present? @stdout_logger = initialize_logger(config.stdout) if config.stdout.present? end |
#debug(*args) ⇒ Object
59 60 61 |
# File 'lib/quandl/command/task/logging.rb', line 59 def debug(*args) args.each{|a| logger.debug("# #{a}") } if verbose? end |
#error(*args) ⇒ Object
63 64 65 |
# File 'lib/quandl/command/task/logging.rb', line 63 def error(*args) stderr_logger.error(*args) end |
#fatal(*args) ⇒ Object
67 68 69 |
# File 'lib/quandl/command/task/logging.rb', line 67 def fatal(*args) stderr_logger.fatal("FATAL: #{args.join(" ")}") end |
#info(*args) ⇒ Object
55 56 57 |
# File 'lib/quandl/command/task/logging.rb', line 55 def info(*args) logger.info(*args) end |
#initialize_logger(path) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/quandl/command/task/logging.rb', line 27 def initialize_logger(path) l = ::Logger.new( path, 2, 52428800 ) l.formatter = proc do |severity, datetime, progname, msg| "# [#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]\n#{msg}" end l end |
#log_request_time ⇒ Object
35 36 37 |
# File 'lib/quandl/command/task/logging.rb', line 35 def log_request_time debug("Started: #{request_timer}. Finished: #{Time.now}. Elapsed: #{request_timer.elapsed_ms}") end |
#logger ⇒ Object
71 72 73 |
# File 'lib/quandl/command/task/logging.rb', line 71 def logger @stdout_logger ||= Quandl::Logger end |
#start_request_timer ⇒ Object
18 19 20 |
# File 'lib/quandl/command/task/logging.rb', line 18 def start_request_timer self.request_timer = Time.now end |
#stderr_logger ⇒ Object
75 76 77 |
# File 'lib/quandl/command/task/logging.rb', line 75 def stderr_logger @stderr_logger ||= Quandl::Logger end |
#summarize(item) ⇒ Object
39 40 41 42 |
# File 'lib/quandl/command/task/logging.rb', line 39 def summarize(item) return summarize_hash(item) if item.kind_of?(Hash) item end |
#summarize_hash(item) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/quandl/command/task/logging.rb', line 44 def summarize_hash(item) item.collect do |k,v| next "#{k}: '#{v}'" if v.kind_of?(String) "#{k}: #{v}" end.join(', ') end |
#table(*args) ⇒ Object
51 52 53 |
# File 'lib/quandl/command/task/logging.rb', line 51 def table(*args) Array(args).flatten.join(" | ") end |