Module: Mongo::Utils Private

Defined in:
lib/mongo/utils.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: LocalLogger

Class Method Summary collapse

Class Method Details

.excerpt_backtrace(exc, **opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Options Hash (**opts):

  • :bg_error_backtrace (true | false | nil | Integer)

    Experimental. Set to true to log complete backtraces for errors in background threads. Set to false or nil to not log backtraces. Provide a positive integer to log up to that many backtrace lines.



47
48
49
50
51
52
53
54
55
56
# File 'lib/mongo/utils.rb', line 47

module_function def excerpt_backtrace(exc, **opts)
  case lines = opts[:bg_error_backtrace]
  when Integer
    ":\n#{exc.backtrace[0..lines].join("\n")}"
  when false, nil
    nil
  else
    ":\n#{exc.backtrace.join("\n")}"
  end
end

.shallow_symbolize_keys(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/mongo/utils.rb', line 58

module_function def shallow_symbolize_keys(hash)
  Hash[hash.map { |k, v| [k.to_sym, v] }]
end

.warn_monitor_exception(msg, exc, **opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Options Hash (**opts):

  • :bg_error_backtrace (true | false | nil | Integer)

    Experimental. Set to true to log complete backtraces for errors in background threads. Set to false or nil to not log backtraces. Provide a positive integer to log up to that many backtrace lines.

  • :logger (Logger)

    A custom logger to use.

  • :log_prefix (String)

    A custom log prefix to use when logging.



37
38
39
40
41
# File 'lib/mongo/utils.rb', line 37

module_function def warn_monitor_exception(msg, exc, **opts)
  bt_excerpt = excerpt_backtrace(exc, **opts)
  logger = LocalLogger.new(**opts)
  logger.log_warn("#{msg}: #{exc.class}: #{exc}#{bt_excerpt}")
end