Class: Omnibus::Logger
- Inherits:
-
Object
- Object
- Omnibus::Logger
- Defined in:
- lib/omnibus/logger.rb
Defined Under Namespace
Classes: LiveStream
Constant Summary collapse
- LEFT =
The amount of padding on the left column.
30
- LEVELS =
Our custom log levels, in order of severity
%w{UNKNOWN INTERNAL DEBUG INFO WARN ERROR FATAL NOTHING}.freeze
- MUTEX =
The mutex lock for synchronizing IO writing.
Mutex.new
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
-
#add(severity, progname, &block) ⇒ Object
Add a message to the logger with the given severity and progname.
-
#deprecated(progname, &block) ⇒ Object
Print a deprecation warning.
-
#initialize(io = $stdout) ⇒ Logger
constructor
Create a new logger object.
-
#inspect ⇒ String
The detailed string representation of this object.
-
#live_stream(level = :debug) ⇒ LiveStream
The live stream for this logger.
-
#to_s ⇒ String
The string representation of this object.
Constructor Details
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
43 44 45 |
# File 'lib/omnibus/logger.rb', line 43 def io @io end |
#level ⇒ Object
Returns the value of attribute level.
44 45 46 |
# File 'lib/omnibus/logger.rb', line 44 def level @level end |
Instance Method Details
#add(severity, progname, &block) ⇒ Object
Add a message to the logger with the given severity and progname.
103 104 105 106 107 108 109 |
# File 'lib/omnibus/logger.rb', line 103 def add(severity, progname, &block) return true if io.nil? || severity < level = (severity, progname, yield) MUTEX.synchronize { io.write() } true end |
#deprecated(progname, &block) ⇒ Object
Print a deprecation warning. This actually outputs to WARN
, but is prefixed with the string “DEPRECATED” first.
71 72 73 74 |
# File 'lib/omnibus/logger.rb', line 71 def deprecated(progname, &block) = Proc.new { "DEPRECATED: #{yield}" } add(LEVELS.index("WARN"), progname, &) end |
#inspect ⇒ String
The detailed string representation of this object.
125 126 127 |
# File 'lib/omnibus/logger.rb', line 125 def inspect "#<#{self.class.name} level: #{@level}>" end |
#live_stream(level = :debug) ⇒ LiveStream
The live stream for this logger.
95 96 97 98 |
# File 'lib/omnibus/logger.rb', line 95 def live_stream(level = :debug) @live_streams ||= {} @live_streams[level.to_sym] ||= LiveStream.new(self, level) end |
#to_s ⇒ String
The string representation of this object.
116 117 118 |
# File 'lib/omnibus/logger.rb', line 116 def to_s "#<#{self.class.name}>" end |