Module: Ougai::Logging

Includes:
Severity
Included in:
ChildLogger, Logger
Defined in:
lib/ougai/logging.rb

Overview

Common Logging features

Defined Under Namespace

Modules: Severity

Constant Summary

Constants included from Severity

Severity::SEV_LABEL, Severity::TRACE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Severity

#to_label

Instance Attribute Details

#before_log=(value) ⇒ Object (writeonly)

Sets the attribute before_log

Parameters:

  • value

    the value to set the attribute before_log to.



5
6
7
# File 'lib/ougai/logging.rb', line 5

def before_log=(value)
  @before_log = value
end

#with_fieldsObject

Returns the value of attribute with_fields.



4
5
6
# File 'lib/ougai/logging.rb', line 4

def with_fields
  @with_fields
end

Instance Method Details

#chain(_severity, _args, _fields, _hooks) ⇒ Object

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/ougai/logging.rb', line 87

def chain(_severity, _args, _fields, _hooks)
  raise NotImplementedError
end

#child(fields = {}) ⇒ ChildLogger

Creates a child logger and returns it.

Parameters:

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

    The fields appending to all logs

Returns:



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

def child(fields = {})
  ChildLogger.new(self, fields)
end

#debug(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as DEBUG. If the block is given for delay evaluation, it returns them as an array or the one of them as a value.

Parameters:

  • message (String) (defaults to: nil)

    The message to log. Use default_message if not specified.

  • ex (Exception) (defaults to: nil)

    The exception or the error

  • data (Object) (defaults to: nil)

    Any structured data

Yield Returns:

  • (String|Exception|Object|Array)

    Any one or more of former parameters

Returns:

  • (Boolean)

    true



33
34
35
# File 'lib/ougai/logging.rb', line 33

def debug(message = nil, ex = nil, data = nil, &block)
  log(DEBUG, message, ex, data, block)
end

#error(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as ERROR.

Returns:

  • (Boolean)

    true

See Also:



54
55
56
# File 'lib/ougai/logging.rb', line 54

def error(message = nil, ex = nil, data = nil, &block)
  log(ERROR, message, ex, data, block)
end

#fatal(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as FATAL.

Returns:

  • (Boolean)

    true

See Also:



61
62
63
# File 'lib/ougai/logging.rb', line 61

def fatal(message = nil, ex = nil, data = nil, &block)
  log(FATAL, message, ex, data, block)
end

#info(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as INFO.

Returns:

  • (Boolean)

    true

See Also:



40
41
42
# File 'lib/ougai/logging.rb', line 40

def info(message = nil, ex = nil, data = nil, &block)
  log(INFO, message, ex, data, block)
end

#trace(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as TRACE.

Returns:

  • (Boolean)

    true

See Also:



22
23
24
# File 'lib/ougai/logging.rb', line 22

def trace(message = nil, ex = nil, data = nil, &block)
  log(TRACE, message, ex, data, block)
end

#trace?Boolean

Whether the current severity level allows for logging TRACE.

Returns:

  • (Boolean)

    true if allows



75
76
77
# File 'lib/ougai/logging.rb', line 75

def trace?
  level <= TRACE
end

#unknown(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as UNKNOWN.

Returns:

  • (Boolean)

    true

See Also:



68
69
70
71
# File 'lib/ougai/logging.rb', line 68

def unknown(message = nil, ex = nil, data = nil, &block)
  args = block ? yield : [message, ex, data]
  append(UNKNOWN, args)
end

#warn(message = nil, ex = nil, data = nil, &block) ⇒ Boolean

Log any one or more of a message, an exception and structured data as WARN.

Returns:

  • (Boolean)

    true

See Also:



47
48
49
# File 'lib/ougai/logging.rb', line 47

def warn(message = nil, ex = nil, data = nil, &block)
  log(WARN, message, ex, data, block)
end