Class: Yell::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/yell/event.rb

Overview

Yell::Event.new( :info, ‘Hello World’, { :scope => ‘Application’ } ) #=> Hello World scope: Application

Defined Under Namespace

Classes: Options

Constant Summary collapse

CallerRegexp =

regex to fetch caller attributes

/^(.+?):(\d+)(?::in `(.+)')?/
CallerIndex =

jruby and rubinius seem to have a different caller

defined?(RUBY_ENGINE) && ["rbx", "jruby"].include?(RUBY_ENGINE) ? 1 : 2
@@hostname =

Prefetch those values (no need to do that on every new instance)

Socket.gethostname rescue nil
@@progname =
$0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, options, *messages, &block) ⇒ Event

Returns a new instance of Event.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/yell/event.rb', line 52

def initialize( logger, options, *messages, &block )
  @time = Time.now
  @name = logger.name

  extract!(options)

  @messages = messages
  @messages << block.call unless block.nil?

  @caller = logger.trace.at?(level) ? caller[caller_index].to_s : ''
  @file = nil
  @line = nil
  @method = nil

  @pid = nil
end

Instance Attribute Details

#levelObject (readonly)

Accessor to the log level



40
41
42
# File 'lib/yell/event.rb', line 40

def level
  @level
end

#messagesObject (readonly)

Accessor to the log message



43
44
45
# File 'lib/yell/event.rb', line 43

def messages
  @messages
end

#nameObject (readonly)

Accessor to the logger’s name



49
50
51
# File 'lib/yell/event.rb', line 49

def name
  @name
end

#timeObject (readonly)

Accessor to the time the log event occured



46
47
48
# File 'lib/yell/event.rb', line 46

def time
  @time
end

Instance Method Details

#fileObject

Accessor to filename the log event occured



90
91
92
# File 'lib/yell/event.rb', line 90

def file
  @file || (backtrace!; @file)
end

#hostnameObject

Accessor to the hostname



70
71
72
# File 'lib/yell/event.rb', line 70

def hostname
  @@hostname
end

#lineObject

Accessor to the line the log event occured



95
96
97
# File 'lib/yell/event.rb', line 95

def line
  @line || (backtrace!; @line)
end

#methodObject

Accessor to the method the log event occured



100
101
102
# File 'lib/yell/event.rb', line 100

def method
  @method || (backtrace!; @method)
end

#pidObject

Accessor to the PID



80
81
82
# File 'lib/yell/event.rb', line 80

def pid
  Process.pid
end

#prognameObject

Accessor to the progname



75
76
77
# File 'lib/yell/event.rb', line 75

def progname
  @@progname
end

#thread_idObject

Accessor to the thread’s id



85
86
87
# File 'lib/yell/event.rb', line 85

def thread_id
  Thread.current.object_id
end