Class: Log15::Logger
- Inherits:
-
Object
- Object
- Log15::Logger
- Defined in:
- lib/log15/logger.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #debug(msg, data = {}) ⇒ Object
- #error(msg, data = {}) ⇒ Object
- #info(msg, data = {}) ⇒ Object
-
#initialize(logger = Rails.logger, context = {}) ⇒ Logger
constructor
A new instance of Logger.
- #new_context(new_context = {}) ⇒ Object
- #warn(msg, data = {}) ⇒ Object
Constructor Details
#initialize(logger = Rails.logger, context = {}) ⇒ Logger
Returns a new instance of Logger.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/log15/logger.rb', line 7 def initialize(logger=Rails.logger, context={}) @context = context @logger = logger.dup @logger.formatter = proc do |severity, datetime, progname, msg| date = "#{datetime.month}-#{datetime.day}" time = "#{pad(datetime.hour)}:#{pad(datetime.min)}:#{pad(datetime.sec)}" severities = { "ERROR" => "EROR", "DEBUG" => "DBUG" } original_severity = severity severity = severities.fetch(severity, severity) "#{severity}[#{date}|#{time}] #{msg} lvl=#{original_severity.downcase}\n" end end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/log15/logger.rb', line 6 def context @context end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/log15/logger.rb', line 6 def logger @logger end |
Class Method Details
.default ⇒ Object
20 21 22 |
# File 'lib/log15/logger.rb', line 20 def self.default @logger ||= Log15::Logger.new end |
.sanitize(params, key, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/log15/logger.rb', line 24 def self.sanitize(params, key, opts={}) if params[key] raise SanitizationError, "expected #{key} to not be blank" if params[key] == "" if opts[:expected_length] minimum_size = opts[:expected_length].first maximum_size = opts[:expected_length].last length = params[key].length if length < minimum_size || length > maximum_size raise SanitizationError, "expected access_token to be between #{minimum_size} and #{maximum_size} characters long (is #{length})" end end params[key] = params[key][0..5] + "****" + params[key][-6..-1] else raise SanitizationError, "expected #{key} to be present" end params end |
Instance Method Details
#debug(msg, data = {}) ⇒ Object
42 43 44 |
# File 'lib/log15/logger.rb', line 42 def debug(msg, data={}) logger.debug(process(msg, data)) end |
#error(msg, data = {}) ⇒ Object
54 55 56 |
# File 'lib/log15/logger.rb', line 54 def error(msg, data={}) logger.error(process(msg, data)) end |
#info(msg, data = {}) ⇒ Object
46 47 48 |
# File 'lib/log15/logger.rb', line 46 def info(msg, data={}) logger.info(process(msg, data)) end |
#new_context(new_context = {}) ⇒ Object
58 59 60 |
# File 'lib/log15/logger.rb', line 58 def new_context(new_context={}) self.class.new(logger, self.context.merge(new_context)) end |
#warn(msg, data = {}) ⇒ Object
50 51 52 |
# File 'lib/log15/logger.rb', line 50 def warn(msg, data={}) logger.warn(process(msg, data)) end |