| Class | BoxGrinder::LogHelper |
| In: |
lib/boxgrinder-core/helpers/log-helper.rb
lib/boxgrinder-core/helpers/log-helper.rb |
| Parent: | Object |
| THRESHOLDS | = | { :trace => Logger::TRACE, :fatal => Logger::FATAL, :debug => Logger::DEBUG, :error => Logger::ERROR, :warn => Logger::WARN, :info => Logger::INFO |
| THRESHOLDS | = | { :trace => Logger::TRACE, :fatal => Logger::FATAL, :debug => Logger::DEBUG, :error => Logger::ERROR, :warn => Logger::WARN, :info => Logger::INFO |
# File lib/boxgrinder-core/helpers/log-helper.rb, line 54
54: def initialize(options = {})
55: location = options[:location] || 'log/boxgrinder.log'
56: threshold = options[:level].nil? ? :info : options[:level].to_sym
57: type = options[:type] || [:stdout, :file]
58:
59: unless type.is_a?(Array)
60: type = [type.to_s.to_sym]
61: end
62:
63: threshold = THRESHOLDS[threshold.to_sym] unless threshold.nil?
64: formatter = Logger::Formatter.new
65:
66: if type.include?(:file)
67: FileUtils.mkdir_p(File.dirname(location))
68:
69: @file_log = Logger.new(location, 10, 1024000)
70: @file_log.level = Logger::TRACE
71: @file_log.formatter = formatter
72: end
73:
74: if type.include?(:stdout)
75: @stdout_log = Logger.new(STDOUT.dup)
76: @stdout_log.level = threshold || Logger::INFO
77: @stdout_log.formatter = formatter
78: end
79: end
# File lib/boxgrinder-core/helpers/log-helper.rb, line 54
54: def initialize(options = {})
55: location = options[:location] || 'log/boxgrinder.log'
56: threshold = options[:level].nil? ? :info : options[:level].to_sym
57: type = options[:type] || [:stdout, :file]
58:
59: unless type.is_a?(Array)
60: type = [type.to_s.to_sym]
61: end
62:
63: threshold = THRESHOLDS[threshold.to_sym] unless threshold.nil?
64: formatter = Logger::Formatter.new
65:
66: if type.include?(:file)
67: FileUtils.mkdir_p(File.dirname(location))
68:
69: @file_log = Logger.new(location, 10, 1024000)
70: @file_log.level = Logger::TRACE
71: @file_log.formatter = formatter
72: end
73:
74: if type.include?(:stdout)
75: @stdout_log = Logger.new(STDOUT.dup)
76: @stdout_log.level = threshold || Logger::INFO
77: @stdout_log.formatter = formatter
78: end
79: end
# File lib/boxgrinder-core/helpers/log-helper.rb, line 86
86: def method_missing(method_name, *args)
87: @stdout_log.send(method_name, *args) unless @stdout_log.nil?
88: @file_log.send(method_name, *args) unless @file_log.nil?
89: end
# File lib/boxgrinder-core/helpers/log-helper.rb, line 86
86: def method_missing(method_name, *args)
87: @stdout_log.send(method_name, *args) unless @stdout_log.nil?
88: @file_log.send(method_name, *args) unless @file_log.nil?
89: end
# File lib/boxgrinder-core/helpers/log-helper.rb, line 81
81: def write( msg )
82: @stdout_log.trace( msg.chomp.strip ) unless @stdout_log.nil?
83: @file_log.trace( msg.chomp.strip ) unless @file_log.nil?
84: end