Class: UU::OS::Logger

Inherits:
Object
  • Object
show all
Defined in:
uu_os_framework-0.29.16/lib/uu/os/logger.rb,
uu_os_framework-0.29.16/lib/uu/os/logger/log_level.rb,
uu_os_framework-0.29.16/lib/uu/os/logger/mdc_provider.rb,
uu_os_framework-0.29.16/lib/uu/os/logger/log4r_plugin.rb

Overview

Logger component.

Defined Under Namespace

Classes: LogLevel

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Logger) initialize(name, options = {})

Creates a new instance of Logger.

Parameters:

  • name (String, Class)

    Logger name. If it is a String, it is used as it is. Otherwise name of its class is used.

  • options (Hash) (defaults to: {})

    Additional logger options. Parameter is optional, actual options depend on particular logger/outputter implementation and are to be found in corresponding documentation.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 22

def initialize(name, options = {})
  raise ArgumentError, 'Logger name is required' unless name
  
  if (name.kind_of?String) && !name.empty?
    logger_name = name
  elsif (name.kind_of?Class)
    logger_name = name.name
  elsif (name.kind_of?Module)
    logger_name = name.name
  else
    logger_name = name.class.name
  end
  @name = logger_name
  
  @plugin = UU::OS::Logger::Log4rPlugin.new(self.name, options)
end

Instance Attribute Details

- (String) name

Logger name.

Returns:

  • (String)


13
14
15
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 13

def name
  @name
end

Instance Method Details

- (Object) debug(msg, exception = nil, *params)

Logs debug message.

Parameters:

  • msg (String)

    Message

  • exception (Exception) (defaults to: nil)

    Exception to be logged (optional)

  • params (Array<String>)

    Message parameters (optional)



92
93
94
95
96
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 92

def debug(msg, exception=nil, *params)
  if debug_loggable?
    self.plugin.debug(msg, exception, *params)
  end
end

- (Boolean) debug_loggable?

Checks if debug messages are enabled.

Returns:

  • (Boolean)


99
100
101
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 99

def debug_loggable?
  return self.plugin.debug_loggable?
end

- (Object) error(msg, exception = nil, *params)

Logs error message.

Parameters:

  • msg (String)

    Message

  • exception (Exception) (defaults to: nil)

    Exception to be logged (optional)

  • params (Array<String>)

    Message parameters (optional)



44
45
46
47
48
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 44

def error(msg, exception=nil, *params)
  if error_loggable?
    self.plugin.error(msg, exception, *params)
  end
end

- (Boolean) error_loggable?

Checks if error messages can be logged.

Returns:

  • (Boolean)


51
52
53
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 51

def error_loggable?
  return self.plugin.error_loggable?
end

- (Object) info(msg, exception = nil, *params)

Logs info message.

Parameters:

  • msg (String)

    Message

  • exception (Exception) (defaults to: nil)

    Exception to be logged (optional)

  • params (Array<String>)

    Message parameters (optional)



76
77
78
79
80
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 76

def info(msg, exception=nil, *params)
  if info_loggable?
    self.plugin.info(msg, exception, *params)
  end
end

- (Boolean) info_loggable?

Checks if info messages are enabled.

Returns:

  • (Boolean)


83
84
85
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 83

def info_loggable?
  return self.plugin.info_loggable?
end

- (Object) level

Returns enabled logger level.



123
124
125
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 123

def level
  return self.plugin.level
end

- (Object) log(level, msg, exception = nil, *params)

Logs message.

Parameters:

  • level (UU::OS::Logger::LogLevel)

    Log level

  • msg (String)

    Message

  • exception (Exception) (defaults to: nil)

    Exception to be logged (optional)

  • params (Array<String>)

    Message parameters (optional)



109
110
111
112
113
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 109

def log(level, msg, exception=nil, *params)
  if loggable?(level)
    self.plugin.log(msg, exception, *params)
  end
end

- (Boolean) loggable?(level)

Checks if given log level is enabled.

Parameters:

Returns:

  • (Boolean)


118
119
120
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 118

def loggable?(level)
  return self.plugin.loggable?(level)
end

- (Object) mdc_put(key, value)

Put a context value as identified by key into mapped diagnostic context. Key and value can be nil.

Parameters:

  • key (String)
  • value (String)


132
133
134
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 132

def mdc_put(key, value)
  self.plugin.mdc_put(key, value)
end

- (Object) mdc_remove(key)

Remove the context identified by the key parameter from mapped diagnostic context. Key can be nil.

Parameters:

  • key (String)


140
141
142
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 140

def mdc_remove(key)
  self.plugin.mdc_remove key
end

- (Object) warning(msg, exception = nil, *params)

Logs warning message.

Parameters:

  • msg (String)

    Message

  • exception (Exception) (defaults to: nil)

    Exception to be logged (optional)

  • params (Array<String>)

    Message parameters (optional)



60
61
62
63
64
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 60

def warning(msg, exception=nil, *params)
  if warning_loggable?
    self.plugin.warning(msg, exception, *params)
  end
end

- (Boolean) warning_loggable?

Checks if warning messages are enabled.

Returns:

  • (Boolean)


67
68
69
# File 'uu_os_framework-0.29.16/lib/uu/os/logger.rb', line 67

def warning_loggable?
  return self.plugin.warning_loggable?
end