Module: LogSanity

Defined in:
lib/log_sanity/formatter.rb,
lib/log_sanity.rb,
lib/log_sanity/railtie.rb,
lib/log_sanity/version.rb,
lib/log_sanity/log_subscribers/base.rb,
lib/log_sanity/middleware/request_logger.rb,
lib/log_sanity/log_subscribers/active_job.rb,
lib/log_sanity/log_subscribers/action_cable.rb,
lib/log_sanity/log_subscribers/action_mailer.rb,
lib/log_sanity/log_subscribers/action_dispatch.rb,
lib/log_sanity/log_subscribers/action_controller.rb,
lib/log_sanity/extensions/action_cable_connection.rb,
lib/log_sanity/extensions/action_controller_helper.rb

Overview

Receives a variety of objects for logging. LogSanity itself sends Hashes which are formatted with #to_json. Other than Strings, will embed any other object into a jsonified hash. Strings are a bit of a special case and by default continue to be formatted with whatever Rails’ formatter originally was. As such, it can be configured using ‘config.log_formatter`. This keeps exception backtraces and other various logs still as Strings. If you prefer Strings to also be turned into jsonified messages, set `config.logsanity.json_strings = true`.

Defined Under Namespace

Modules: Extensions, LogSubscriber Classes: Formatter, Railtie, RequestLogger

Constant Summary collapse

VERSION =
'2.3.1'

Class Method Summary collapse

Class Method Details

.fieldsObject



20
21
22
23
# File 'lib/log_sanity.rb', line 20

def fields
  # this is fiber-local
  Thread.current[:logsanity_fields] || reset_fields
end

.log(key, val) ⇒ Object



29
30
31
# File 'lib/log_sanity.rb', line 29

def log(key, val)
  fields[key.to_s] = val
end

.reset_fieldsObject



25
26
27
# File 'lib/log_sanity.rb', line 25

def reset_fields
  Thread.current[:logsanity_fields] = {}.with_indifferent_access
end