Module: Fig::Logging

Defined in:
lib/fig/logging.rb

Overview

Logging facility that handles the fact that we may wish to do logging prior to Log4r being properly configured.

Constant Summary collapse

STRING_TO_LEVEL_MAPPING =
{
  'off'   => Log4r::OFF,
  'fatal' => Log4r::FATAL,
  'error' => Log4r::ERROR,
  'warn'  => Log4r::WARN,
  'info'  => Log4r::INFO,
  'debug' => Log4r::DEBUG,
  'all'   => Log4r::ALL
}
@@logger =
Log4r::Logger.new('initial')

Class Method Summary collapse

Class Method Details

.debug(data = nil, propagated = nil) ⇒ Object



106
107
108
# File 'lib/fig/logging.rb', line 106

def self.debug(data = nil, propagated = nil)
  @@logger.debug data, propagated
end

.debug?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/fig/logging.rb', line 110

def self.debug?()
  return @@logger.debug?
end

.error(data = nil, propagated = nil) ⇒ Object



82
83
84
# File 'lib/fig/logging.rb', line 82

def self.error(data = nil, propagated = nil)
  @@logger.error data, propagated
end

.error?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/fig/logging.rb', line 86

def self.error?()
  return @@logger.error?
end

.fatal(data = nil, propagated = nil) ⇒ Object



74
75
76
# File 'lib/fig/logging.rb', line 74

def self.fatal(data = nil, propagated = nil)
  @@logger.fatal data, propagated
end

.fatal?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/fig/logging.rb', line 78

def self.fatal?()
  return @@logger.fatal?
end

.info(data = nil, propagated = nil) ⇒ Object



98
99
100
# File 'lib/fig/logging.rb', line 98

def self.info(data = nil, propagated = nil)
  @@logger.info data, propagated
end

.info?Boolean

Returns:

  • (Boolean)


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

def self.info?()
  return @@logger.info?
end

.initialize_post_configuration(config_file = nil, log_level = nil, suppress_default_configuration = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fig/logging.rb', line 34

def self.initialize_post_configuration(
  config_file = nil,
  log_level = nil,
  suppress_default_configuration = false
)
  if config_file
    begin
      case config_file
        when / [.] xml \z /x
          Log4r::Configurator.load_xml_file(config_file)
        when / [.] ya?ml \z /x
          Log4r::YamlConfigurator.load_yaml_file(config_file)
        else
          raise ConfigFileError, %Q<Don't know what format #{config_file} is in.>, config_file
      end

      if Log4r::Logger['fig'].nil?
        $stderr.puts %q<A value was provided for --log-config but no "fig" logger was defined.>
      end
    rescue Log4r::ConfigError, ArgumentError => exception
      raise Log4rConfigError.new(config_file, exception)
    end
  end

  if Log4r::Logger['fig'].nil?
    @@logger = Log4r::Logger.new('fig')
  else
    @@logger = Log4r::Logger['fig']
  end

  if not config_file and not suppress_default_configuration
    assign_log_level(@@logger, 'info')
    setup_default_outputter(@@logger)
  end

  assign_log_level(@@logger, log_level)

  return
end

.initialize_pre_configuration(log_level = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/fig/logging.rb', line 27

def self.initialize_pre_configuration(log_level = nil)
  log_level ||= 'info'

  assign_log_level(@@logger, log_level)
  setup_default_outputter(@@logger)
end

.warn(data = nil, propagated = nil) ⇒ Object



90
91
92
# File 'lib/fig/logging.rb', line 90

def self.warn(data = nil, propagated = nil)
  @@logger.warn data, propagated
end

.warn?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/fig/logging.rb', line 94

def self.warn?()
  return @@logger.warn?
end