Module: BetterController::Logging

Extended by:
ActiveSupport::Concern
Defined in:
lib/better_controller/logging.rb

Overview

Module providing logging capabilities

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#log_debug(message, tags = {}) ⇒ Object

Log a message at the debug level

Parameters:

  • message (String)

    The message to log

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

    Additional tags for the log



23
24
25
# File 'lib/better_controller/logging.rb', line 23

def log_debug(message, tags = {})
  log(:debug, message, tags)
end

#log_error(message, tags = {}) ⇒ Object

Log a message at the error level

Parameters:

  • message (String)

    The message to log

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

    Additional tags for the log



37
38
39
# File 'lib/better_controller/logging.rb', line 37

def log_error(message, tags = {})
  log(:error, message, tags)
end

#log_exception(exception, tags = {}) ⇒ Object

Log an exception

Parameters:

  • exception (Exception)

    The exception to log

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

    Additional tags for the log



51
52
53
54
55
56
57
58
59
60
# File 'lib/better_controller/logging.rb', line 51

def log_exception(exception, tags = {})
  return unless BetterController.config.error_handling[:log_errors]

  tags = tags.merge(
    exception_class: exception.class.name,
    backtrace:       exception.backtrace&.join("\n")
  )

  log_error(exception.message, tags)
end

#log_fatal(message, tags = {}) ⇒ Object

Log a message at the fatal level

Parameters:

  • message (String)

    The message to log

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

    Additional tags for the log



44
45
46
# File 'lib/better_controller/logging.rb', line 44

def log_fatal(message, tags = {})
  log(:fatal, message, tags)
end

#log_info(message, tags = {}) ⇒ Object

Log a message at the info level

Parameters:

  • message (String)

    The message to log

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

    Additional tags for the log



16
17
18
# File 'lib/better_controller/logging.rb', line 16

def log_info(message, tags = {})
  log(:info, message, tags)
end

#log_warn(message, tags = {}) ⇒ Object

Log a message at the warn level

Parameters:

  • message (String)

    The message to log

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

    Additional tags for the log



30
31
32
# File 'lib/better_controller/logging.rb', line 30

def log_warn(message, tags = {})
  log(:warn, message, tags)
end