Class: Aspector::Logger

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

Constant Summary collapse

ERROR =

Log levels

50
WARN =
40
INFO =
30
DEBUG =
20
TRACE =
10
DEFAULT_VISIBLE_LEVEL =
INFO
DEFINE_ADVICE =

Actions

["define-advice"  , INFO]
APPLY =
["apply"          , INFO]
APPLY_TO_METHOD =
["apply-to-method", DEBUG]
ENABLE_ASPECT =
["enable-aspect"  , INFO]
DISABLE_ASPECT =
["disable-aspect" , INFO]
GENERATE_CODE =
["generate-code"  , DEBUG]
ENTER_GENERATED_METHOD =
["enter-generated-method", TRACE]
EXIT_GENERATED_METHOD =
["exit--generated-method", TRACE]
EXIT_BECAUSE_DISABLED =
["exit--because-disabled", TRACE]
BEFORE_INVOKE_ADVICE =
["before-invoke-advice"  , TRACE]
AFTER_INVOKE_ADVICE =
["after--invoke-advice"  , TRACE]
BEFORE_WRAPPED_METHOD =
["before-wrapped-method" , TRACE]
AFTER_WRAPPED_METHOD =
["after--wrapped-method" , TRACE]
BEFORE_INVOKE_PROXY =
["before-invoke-proxy"   , TRACE]
AFTER_INVOKE_PROXY =
["after--invoke-proxy"   , TRACE]
METHOD_NOT_FOUND =

Unexpected behaviors

["method-not-found"      , WARN]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, level = nil) ⇒ Logger

Returns a new instance of Logger.



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

def initialize context, level = nil
  @context = context
  @level = level
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#levelObject



41
42
43
44
45
46
47
48
49
# File 'lib/aspector/logger.rb', line 41

def level
  return @level if @level

  if (level_string = ENV['ASPECTOR_LOG_LEVEL'])
    @level = string_to_level(level_string)
  else
    @level = DEFAULT_VISIBLE_LEVEL
  end
end

Instance Method Details

#log(action_level, *args) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/aspector/logger.rb', line 51

def log action_level, *args
  action, level = *action_level

  return if self.level > level

  puts log_prefix(level) << action << " | " << args.join(" | ")
end

#log_method_call(method, action_level, *args) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/aspector/logger.rb', line 59

def log_method_call method, action_level, *args
  action, level = *action_level

  return if self.level > level

  puts log_prefix(level) << method << " | " << action << " | " << args.join(" | ")
end

#visible?(level) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/aspector/logger.rb', line 67

def visible? level
  self.level <= level
end