Class: Yell::Event
- Inherits:
-
Object
- Object
- Yell::Event
- 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
- @@progname =
$0
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Accessor to the log level.
-
#messages ⇒ Object
readonly
Accessor to the log messages.
-
#pid ⇒ Object
readonly
Accessor to the pid.
-
#thread_id ⇒ Object
readonly
Accessor to the current tread_id.
-
#time ⇒ Object
readonly
Accessor to the time the log event occured.
Instance Method Summary collapse
-
#file ⇒ Object
Accessor to filename the log event occured.
-
#hostname ⇒ Object
Accessor to the hostname.
-
#initialize(level, *messages, &block) ⇒ Event
constructor
A new instance of Event.
-
#line ⇒ Object
Accessor to the line the log event occured.
-
#method ⇒ Object
Accessor to the method the log event occured.
-
#progname ⇒ Object
Accessor to the progname.
Constructor Details
#initialize(level, *messages, &block) ⇒ Event
Returns a new instance of Event.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yell/event.rb', line 38 def initialize( level, *, &block ) @pid = Process.pid @time = Time.now @level = level @messages = @messages << block.call if block @thread_id = Thread.current.object_id @caller = caller[CallerIndex].to_s @file = nil @line = nil @method = nil end |
Instance Attribute Details
#level ⇒ Object (readonly)
Accessor to the log level
26 27 28 |
# File 'lib/yell/event.rb', line 26 def level @level end |
#messages ⇒ Object (readonly)
Accessor to the log messages
29 30 31 |
# File 'lib/yell/event.rb', line 29 def @messages end |
#pid ⇒ Object (readonly)
Accessor to the pid
23 24 25 |
# File 'lib/yell/event.rb', line 23 def pid @pid end |
#thread_id ⇒ Object (readonly)
Accessor to the current tread_id
35 36 37 |
# File 'lib/yell/event.rb', line 35 def thread_id @thread_id end |
#time ⇒ Object (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
#file ⇒ Object
Accessor to filename the log event occured
65 66 67 68 |
# File 'lib/yell/event.rb', line 65 def file _caller! if @file.nil? @file end |
#hostname ⇒ Object
Accessor to the hostname
55 56 57 |
# File 'lib/yell/event.rb', line 55 def hostname @@hostname end |
#line ⇒ Object
Accessor to the line the log event occured
71 72 73 74 |
# File 'lib/yell/event.rb', line 71 def line _caller! if @line.nil? @line end |
#method ⇒ Object
Accessor to the method the log event occured
77 78 79 80 |
# File 'lib/yell/event.rb', line 77 def method _caller! if @method.nil? @method end |
#progname ⇒ Object
Accessor to the progname
60 61 62 |
# File 'lib/yell/event.rb', line 60 def progname @@progname end |