Module: Logify
- Defined in:
- lib/logify.rb,
lib/logify/logger.rb,
lib/logify/version.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods Classes: Logger
Constant Summary collapse
- LEVEL_ID =
'logify.level'- IO_ID =
'logify.io'- VERSION =
The Logify version
'0.1.0'
Class Method Summary collapse
- .included(base) ⇒ Object
-
.io ⇒ IO
The IO stream to log to.
-
.io=(io) ⇒ IO
Set the global io object.
-
.level ⇒ Fixnum
The current log level.
-
.level=(id) ⇒ Fixnum
Set the global log level.
- .logger_for(name) ⇒ Object
-
.reset! ⇒ true
Reset the current loggers for all thread instances.
Class Method Details
.included(base) ⇒ Object
13 14 15 16 |
# File 'lib/logify.rb', line 13 def included(base) base.send(:extend, ClassMethods) base.send(:include, InstanceMethods) end |
.io ⇒ IO
The IO stream to log to. Default: $stdout.
68 69 70 |
# File 'lib/logify.rb', line 68 def io Thread.current[IO_ID] || Thread.main[IO_ID] || $stdout end |
.io=(io) ⇒ IO
Set the global io object. All loggers in the current thread will immediately begin using this new IO stream. It is the user’s responsibility to manage this IO object (like rewinding and closing).
89 90 91 |
# File 'lib/logify.rb', line 89 def io=(io) Thread.current[IO_ID] = io end |
.level ⇒ Fixnum
The current log level.
43 44 45 |
# File 'lib/logify.rb', line 43 def level Thread.current[LEVEL_ID] || Thread.main[LEVEL_ID] || Logger::DEFAULT end |
.level=(id) ⇒ Fixnum
Set the global log level. All loggers in the current thread will immediately begin using this new log level.
59 60 61 |
# File 'lib/logify.rb', line 59 def level=(id) Thread.current[LEVEL_ID] = Logger::LEVEL_MAP.fetch(id, Logger::DEFAULT) end |
.logger_for(name) ⇒ Object
19 20 21 |
# File 'lib/logify.rb', line 19 def logger_for(name) loggers[name] ||= Logger.new(name) end |
.reset! ⇒ true
Reset the current loggers for all thread instances.
28 29 30 31 32 33 34 35 36 |
# File 'lib/logify.rb', line 28 def reset! Thread.list.each do |thread| thread[LEVEL_ID] = nil thread[IO_ID] = nil end loggers.clear true end |