module Logify
Constants
- IO_ID
@private
- LEVEL_ID
@private
- VERSION
The
Logify
version@return [String]
Public Class Methods
Add a filter parameter to Logify
.
@example Filter a password in the logger
Logify.filter('P@s$w0r)') log.debug "This is the P@s$w0r)" #=> "This is the [FILTERED]"
@return [void]
# File lib/logify.rb, line 102 def filter(param) filters[param] = nil end
The list of filters for Logify
.
@return [Hash]
# File lib/logify.rb, line 111 def filters @filters ||= {} end
@private
# File lib/logify.rb, line 13 def included(base) base.send(:extend, ClassMethods) base.send(:include, InstanceMethods) end
The IO stream to log to. Default: +$stdout+.
@return [IO]
# File lib/logify.rb, line 68 def io Thread.current[IO_ID] || Thread.main[IO_ID] || $stdout end
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).
@example Setting the outputter to +$stderr+
Logify.io = $stderr
@example Using an IO object
io = StringIO.new Logify.io = io
@param [IO] io
the IO object to output to
@return [IO]
# File lib/logify.rb, line 89 def io=(io) Thread.current[IO_ID] = io end
The current log level.
@return [Fixnum]
# File lib/logify.rb, line 43 def level Thread.current[LEVEL_ID] || Thread.main[LEVEL_ID] || Logger::DEFAULT end
Set the global log level. All loggers in the current thread will immediately begin using this new log level.
@example Setting the log level to :fatal
Logify.level = :fatal
@param [Symbol] id
the symbol id of the logger
@return [Fixnum]
# File lib/logify.rb, line 59 def level=(id) Thread.current[LEVEL_ID] = Logger::LEVEL_MAP.fetch(id, Logger::DEFAULT) end
@private
# File lib/logify.rb, line 19 def logger_for(name) loggers[name] ||= Logger.new(name) end
Reset the current loggers for all thread instances.
@return [true]
# 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
Private Class Methods
@private
# File lib/logify.rb, line 118 def loggers @loggers ||= {} end