Module: TTY::Logger::Handlers::Base

Included in:
Console, Stream
Defined in:
lib/tty/logger/handlers/base.rb

Instance Method Summary collapse

Instance Method Details

#coerce_formatter(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce formatter name into constant



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tty/logger/handlers/base.rb', line 23

def coerce_formatter(name)
  case name
  when String, Symbol
    const_name = if Formatters.const_defined?(name.upcase)
                   name.upcase
                 else
                   name.capitalize
                 end
    Formatters.const_get(const_name)
  when Class
    name
  else
    raise_formatter_error(name)
  end
rescue NameError
  raise_formatter_error(name)
end

#format_filepath(event) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Format path from event metadata

Returns:

  • (String)


66
67
68
69
# File 'lib/tty/logger/handlers/base.rb', line 66

def format_filepath(event)
  "%s:%d:in`%s`" % [event.[:path], event.[:lineno],
                    event.[:method]]
end

#log_at(tmp_level) ⇒ Object

Change current log level for the duration of the block

Parameters:

  • tmp_level (String)

    the temporary log level



13
14
15
16
17
18
# File 'lib/tty/logger/handlers/base.rb', line 13

def log_at(tmp_level)
  old_level, @level = level, tmp_level
  yield
ensure
  @level = old_level
end

#metadataArray[Symbol]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Metadata for the log event

Returns:

  • (Array[Symbol])


53
54
55
56
57
58
59
# File 'lib/tty/logger/handlers/base.rb', line 53

def 
  if config..include?(:all)
    [:pid, :date, :time, :file]
  else
    config.
  end
end

#raise_formatter_error(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raise error when unknown formatter name

Raises:



44
45
46
# File 'lib/tty/logger/handlers/base.rb', line 44

def raise_formatter_error(name)
  raise Error, "Unrecognized formatter name '#{name.inspect}'"
end