Class: EnhancedLogger::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/enhanced_logger/logger.rb

Constant Summary collapse

LEVELS =
{ debug:0, info:1, warn:2, error:3, fatal:4, unknown:5 }.freeze
MAX_UUID_LENGTH =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = 1, options = nil) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/enhanced_logger/logger.rb', line 6

def level
  @level
end

Instance Method Details

#clear_envObject



24
25
26
27
# File 'lib/enhanced_logger/logger.rb', line 24

def clear_env
  @request_id = nil
  @remote_request_id = nil
end

#debug(msg = nil) ⇒ Object



50
51
52
# File 'lib/enhanced_logger/logger.rb', line 50

def debug msg=nil
  puts formatted( msg ) if debug?
end

#debug?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/enhanced_logger/logger.rb', line 29

def debug?
  @level <= LEVELS[ :debug ]
end

#error(msg = nil) ⇒ Object



62
63
64
# File 'lib/enhanced_logger/logger.rb', line 62

def error msg=nil
  puts formatted( msg ) if error?
end

#error?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/enhanced_logger/logger.rb', line 41

def error?
  @level <= LEVELS[ :error ]
end

#fatal(msg = nil) ⇒ Object



66
67
68
# File 'lib/enhanced_logger/logger.rb', line 66

def fatal msg=nil
  puts formatted( msg ) if fatal?
end

#fatal?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/enhanced_logger/logger.rb', line 45

def fatal?
  @level <= LEVELS[ :fatal ]
end

#formatterObject



70
71
72
# File 'lib/enhanced_logger/logger.rb', line 70

def formatter
  ''
end

#info(msg = nil) ⇒ Object



54
55
56
# File 'lib/enhanced_logger/logger.rb', line 54

def info msg=nil
  puts formatted( msg ) if info?
end

#info?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/enhanced_logger/logger.rb', line 33

def info?
  @level <= LEVELS[ :info ]
end

#most_recent_callerObject



74
75
76
77
78
# File 'lib/enhanced_logger/logger.rb', line 74

def most_recent_caller
  regex_str = '[' + @options[ :exclude_files ].join( '|' ) + ']'
  
  caller.find{| c | c !~ %r+#{ regex_str }\.rb+ }.split( '/' ).last
end

#set_env(env) ⇒ Object



19
20
21
22
# 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) ⇒ Object



58
59
60
# File 'lib/enhanced_logger/logger.rb', line 58

def warn msg=nil
  puts formatted( msg ) if warn?
end

#warn?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/enhanced_logger/logger.rb', line 37

def warn?
  @level <= LEVELS[ :warn ]
end