Inspired by Keep a Changelog.
Note: this project adheres to Semantic Versioning.
- Added support for
activesupport
7.1 by providing a mixin for extending Broadcast loggers.
ContextualLogger::LoggerMixin#redact
method to expose the existing redaction logic outside of just logs.
- Limit
activesupport
gem to versions less than 7.1 due to a bug with ActiveSupport Broadcast interface changes.
- Changed global_context to be stored inside the logger.
- Changed current_context to be stored in a Thread/Fiber-local variable that is unique per instance of the logger.
- Changed
LoggerWithContext
to honorwith_context
on itself and the base logger.
- Bug fix for registering regex
- Added specs around registering regex delegation
- renamed function registering_regex to registering_secret_regex
- Added support for registering regex for secret redaction
- Added official support for Ruby 3+
- Updated contextual logger to normalize keys to symbols and warn on string keys
- Added support and tests for all combinations of
progname
,message
, andcontext
:
logger.info(message)
logger.info(context_key1: value, context_key2: value)
logger.info(message, context_key1: value, context_key2: value)
logger.info { message }
logger.info(progname) { message }
logger.info(context_key1: value, context_key2: value) { message }
logger.info(progname, context_key1: value, context_key2: value) { message }
including where progname
and message
are types other than String
.
- Fixed bug where usage like in Faraday:
logger.info(progname) { message }
was dropping the message and only showingprogname
. - Fixed bug in block form where the message block would be called even if the log_level was not enabled (this could have been slow).
- Fixed bug where merging context with string keys was causing a "key" is not a Symbol error
- Removed unnecessary duplicate context (
severity
,timestamp
, andprogname
) in message hash passed to formatter. These are already passed to the formatter as arguments so that the formatter can decide how to add them to the log line.
- Added support for rails 5 and 6.
- Added appraisal tests for all supported rails version: 4/5/6
- Updated various test to be compatible with rails version 4/5/6
- Updated the CI pipeline to test against all three supported versions of rails
- Fixed undefined method
delegate
bug in ActiveSupport version 4
- Deprecated ContextualLogger.new. It will be removed in version 1.0.
Instead, use
expect ContextualLogger::LoggerMixin
on a logger instance orinclude ContextualLogger::LoggerMixin
in a Logger class.
- Fixed gemspec to point to correct source code uri
- Added the ability to redact sensitive data from log entries by registering the sensitive strings ahead of time with the logger
- Added
ContextualLogger#normalize_message
as a general logging helper method to normalize any message to string format.
-
Restored ::Logger's ability to log non-string messages like
nil
orfalse
, in case there's a gem we use someday that depends on that. -
JSON logging now logs all messages as strings, by calling
normalize_message
, above. Previously, messages were converted by.to_json
, sonil
was logged as JSONnull
; now it is logged as the string"nil"
. Similarly,false
was logged as JSONfalse
; now it is logged as the string"false"
.
- Fixed Rails Server logging to STDOUT: Refactored debug, info, error... etc methods to call the base class
add(severity, message, progrname)
method sinceActiveSupport::Logger.broadcast
reimplements that to broadcast to multiple logger instances, such asRails::Server
logging toSTDOUT
+development.log
. Note that the base classadd()
does not have acontext
hash like ouradd()
does. We use the**
splat to match thecontext
hash up to the extra**context
argument, if present. If that argument is not present (such as withbroadcast
), Ruby will instead match the**context
up to theprogname
argument.
- Extracted
ContextualLogger.normalize_log_level
into a public class method so we can call it elsewhere where we allow log_level to be configured to text values like 'debug'.