class EnhancedLogger::Logger
Constants
- LEVELS
- MAX_UUID_LENGTH
Attributes
level[RW]
Public Class Methods
new(level=1, options=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 8 def initialize level=1, options=nil options ||= {} @options = {} @level = level @options[ :exclude_files ] = Array( options[ :exclude_files ]).push filename @options[ :uuid_log_length ] = options[ :uuid_log_length ] $stdout.sync = true end
Public Instance Methods
clear_env()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 24 def clear_env @request_id = nil @remote_request_id = nil end
debug(msg=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 49 def debug msg=nil return if is_not_a_message?( msg ) puts formatted( msg ) if debug? end
debug?()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 29 def debug? @level <= LEVELS[ :debug ] end
error(msg=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 64 def error msg=nil return if is_not_a_message?( msg ) puts formatted( msg ) if error? end
error?()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 41 def error? @level <= LEVELS[ :error ] end
fatal(msg=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 69 def fatal msg=nil return if is_not_a_message?( msg ) puts formatted( msg ) if fatal? end
fatal?()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 45 def fatal? @level <= LEVELS[ :fatal ] end
formatter()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 74 def formatter '' end
info(msg=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 54 def info msg=nil return if is_not_a_message?( msg ) puts formatted( msg ) if info? end
info?()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 33 def info? @level <= LEVELS[ :info ] end
most_recent_caller()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 78 def most_recent_caller regex_str = '[' + @options[ :exclude_files ].join( '|' ) + ']' filtered = caller.find{| c | c !~ %r+#{ regex_str }\.rb+ } filtered.nil? ? '' : filtered.split( '/' ).last end
set_env(env)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 19 def set_env env @request_id = env[ 'HTTP_X_REQUEST_ID' ] @remote_request_id = env[ 'HTTP_X_REMOTE_REQUEST_ID' ] end
warn(msg=nil)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 59 def warn msg=nil return if is_not_a_message?( msg ) puts formatted( msg ) if warn? end
warn?()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 37 def warn? @level <= LEVELS[ :warn ] end
Private Instance Methods
filename()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 92 def filename File.basename( __FILE__ ).gsub '.rb', '' end
formatted(msg)
click to toggle source
# File lib/enhanced_logger/logger.rb, line 96 def formatted msg previous = most_recent_caller parts = previous.split( /[\.|:]/ ) method = previous.split( /`/ ).last.gsub( "'", "" ) remote_request_id = @remote_request_id.to_s[ 0..uuid_log_length-1 ] request_id = @request_id.to_s[ 0..uuid_log_length-1 ] "#{ remote_request_id } #{ request_id } #{ parts[ 0 ]} #{ method } #{ parts[ 2 ]}: #{ msg }" end
is_not_a_message?( msg )
click to toggle source
# File lib/enhanced_logger/logger.rb, line 88 def is_not_a_message?( msg ) msg.nil? || msg.is_a?( String ) && msg.empty? end
uuid_log_length()
click to toggle source
# File lib/enhanced_logger/logger.rb, line 107 def uuid_log_length @options[ :uuid_log_length ] || MAX_UUID_LENGTH end