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

Returns:

  • (String)
'0.2.0'

Class Method Summary collapse

Class Method Details

.filter(param) ⇒ void

This method returns an undefined value.

Add a filter parameter to Logify.

Examples:

Filter a password in the logger

Logify.filter('P@s$w0r)')
log.debug "This is the P@s$w0r)" #=> "This is the [FILTERED]"


102
103
104
# File 'lib/logify.rb', line 102

def filter(param)
  filters[param] = nil
end

.filtersHash

The list of filters for Logify.

Returns:

  • (Hash)


111
112
113
# File 'lib/logify.rb', line 111

def filters
  @filters ||= {}
end

.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

.ioIO

The IO stream to log to. Default: $stdout.

Returns:

  • (IO)


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).

Examples:

Setting the outputter to $stderr

Logify.io = $stderr

Using an IO object

io = StringIO.new
Logify.io = io

Parameters:

  • io (IO)

    the IO object to output to

Returns:

  • (IO)


89
90
91
# File 'lib/logify.rb', line 89

def io=(io)
  Thread.current[IO_ID] = io
end

.levelFixnum

The current log level.

Returns:

  • (Fixnum)


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.

Examples:

Setting the log level to :fatal

Logify.level = :fatal

Parameters:

  • id (Symbol)

    the symbol id of the logger

Returns:

  • (Fixnum)


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.

Returns:

  • (true)


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