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.
-
#name ⇒ Object
readonly
Accessor to the logger’s name.
-
#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(logger, 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.
-
#pid ⇒ Object
Accessor to the PID.
-
#progname ⇒ Object
Accessor to the progname.
-
#thread_id ⇒ Object
Accessor to the thread’s id.
Constructor Details
#initialize(logger, level, *messages, &block) ⇒ Event
Returns a new instance of Event.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yell/event.rb', line 34 def initialize(logger, level, *, &block) @time = Time.now @level = level @name = logger.name @messages = @messages << block.call if block @caller = logger.trace.at?(level) ? caller[CallerIndex].to_s : '' @file = nil @line = nil @method = nil @pid = nil end |
Instance Attribute Details
#level ⇒ Object (readonly)
Accessor to the log level
22 23 24 |
# File 'lib/yell/event.rb', line 22 def level @level end |
#messages ⇒ Object (readonly)
Accessor to the log messages
25 26 27 |
# File 'lib/yell/event.rb', line 25 def @messages end |
#name ⇒ Object (readonly)
Accessor to the logger’s name
31 32 33 |
# File 'lib/yell/event.rb', line 31 def name @name end |
#time ⇒ Object (readonly)
Accessor to the time the log event occured
28 29 30 |
# File 'lib/yell/event.rb', line 28 def time @time end |
Instance Method Details
#file ⇒ Object
Accessor to filename the log event occured
71 72 73 |
# File 'lib/yell/event.rb', line 71 def file @file || (backtrace!; @file) end |
#hostname ⇒ Object
Accessor to the hostname
51 52 53 |
# File 'lib/yell/event.rb', line 51 def hostname @@hostname end |
#line ⇒ Object
Accessor to the line the log event occured
76 77 78 |
# File 'lib/yell/event.rb', line 76 def line @line || (backtrace!; @line) end |
#method ⇒ Object
Accessor to the method the log event occured
81 82 83 |
# File 'lib/yell/event.rb', line 81 def method @method || (backtrace!; @method) end |
#pid ⇒ Object
Accessor to the PID
61 62 63 |
# File 'lib/yell/event.rb', line 61 def pid Process.pid end |
#progname ⇒ Object
Accessor to the progname
56 57 58 |
# File 'lib/yell/event.rb', line 56 def progname @@progname end |
#thread_id ⇒ Object
Accessor to the thread’s id
66 67 68 |
# File 'lib/yell/event.rb', line 66 def thread_id Thread.current.object_id end |