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

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
@@pid =
Process.pid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, message = nil, options = {}, &block) ⇒ Event

Returns a new instance of Event.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yell/event.rb', line 38

def initialize( level, message = nil, options = {}, &block )
  @time     = Time.now
  @level    = level
  @message  = block ? block.call : message
  @options  = options

  @thread_id  = Thread.current.object_id

  @caller = caller[CallerIndex].to_s
  @file   = nil
  @line   = nil
  @method = nil
end

Instance Attribute Details

#levelObject (readonly)

Accessor to the log level



23
24
25
# File 'lib/yell/event.rb', line 23

def level
  @level
end

#messageObject (readonly)

Accessor to the log message



26
27
28
# File 'lib/yell/event.rb', line 26

def message
  @message
end

#optionsObject (readonly)

Accessor to additional options



29
30
31
# File 'lib/yell/event.rb', line 29

def options
  @options
end

#thread_idObject (readonly)

Accessor to the current tread_id



35
36
37
# File 'lib/yell/event.rb', line 35

def thread_id
  @thread_id
end

#timeObject (readonly)

Accessor to the time the log event occured



32
33
34
# File 'lib/yell/event.rb', line 32

def time
  @time
end

Instance Method Details

#fileObject

Accessor to filename the log event occured



63
64
65
66
# File 'lib/yell/event.rb', line 63

def file
  _caller! if @file.nil?
  @file
end

#hostnameObject

Accessor to the pid



53
54
55
# File 'lib/yell/event.rb', line 53

def hostname
  @@hostname
end

#lineObject

Accessor to the line the log event occured



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

def line
  _caller! if @line.nil?
  @line
end

#methodObject

Accessor to the method the log event occured



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

def method
  _caller! if @method.nil?
  @method
end

#pidObject

Accessor to the hostname



58
59
60
# File 'lib/yell/event.rb', line 58

def pid
  @@pid
end