Class: UU::OS::Logger

Inherits:
Object
  • Object
show all
Defined in:
uu_os_framework-0.10.6/lib/uu/os/logger.rb,
uu_os_framework-0.10.6/lib/uu/os/logger/log_level.rb,
uu_os_framework-0.10.6/lib/uu/os/logger/mdc_provider.rb,
uu_os_framework-0.10.6/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)


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

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)


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

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)



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

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)


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

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)



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

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)


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

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)



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

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)


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

def info_loggable?
  return self.plugin.info_loggable?
end

- (Object) level

Returns enabled logger level.



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

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)



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

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)


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

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)


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

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)


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

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)



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

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)


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

def warning_loggable?
  return self.plugin.warning_loggable?
end