class DTK::Agent::Log

Constants

LOGS_DIR
LOG_TO_CONSOLE
LOG_TO_FILE

Attributes

all_msgs[RW]
error_msgs[RW]
logger[RW]

Public Class Methods

debug(msg) click to toggle source
# File lib/logger.rb, line 33
def self.debug(msg)
  # self.instance.logger.debug(msg)
  ap "debug: #{msg}" if LOG_TO_CONSOLE
end
error(msg, backtrace = nil) click to toggle source
# File lib/logger.rb, line 49
def self.error(msg, backtrace = nil)
  # self.instance.logger.error(msg)
  ap "error: #{msg}" if LOG_TO_CONSOLE
  self.instance.error_msgs << { :message => msg, :backtrace => backtrace }
end
execution_errors() click to toggle source
# File lib/logger.rb, line 29
def self.execution_errors()
  self.instance.error_msgs
end
info(msg) click to toggle source
# File lib/logger.rb, line 38
def self.info(msg)
  # self.instance.logger.info(msg)
  ap "info: #{msg}" if LOG_TO_CONSOLE
end
log_results(params_in, results, component_name, action_name, top_task_id, task_id) click to toggle source
# File lib/logger.rb, line 55
def self.log_results(params_in, results, component_name, action_name, top_task_id, task_id)
  component_dir = File.join(LOGS_DIR, "#{component_name}_#{top_task_id}")
  FileUtils.mkdir_p(component_dir) unless File.directory?(component_dir)

  filename = File.join(component_dir, "#{task_id}_#{action_name}.log")
  File.open(filename, 'w') do |file|
    file.puts('Input data: ')
    file.puts JSON.pretty_generate(params_in)
    file.puts self.instance.all_msgs.join("\n")
    file.puts('Results: ')
    file.puts JSON.pretty_generate(results)
  end
end
new() click to toggle source

LOG_TO_FILE = '/Users/haris/test.log'

# File lib/logger.rb, line 21
def initialize
  # @logger = Logger.new(File.new(LOG_TO_FILE,'w'))
  @all_msgs   =[]
  @error_msgs =[]

  FileUtils.mkdir_p LOGS_DIR unless File.directory?(LOGS_DIR)
end
warn(msg, backtrace = nil) click to toggle source
# File lib/logger.rb, line 43
def self.warn(msg, backtrace = nil)
  # self.instance.logger.warn(msg)
  ap "warn: #{msg}" if LOG_TO_CONSOLE
  self.instance.error_msgs <<  { :message => msg, :backtrace => backtrace }
end