Skip to content

Conversation

ColinDKelley
Copy link
Contributor

Introduces new LoggerWithContext class. Example usage:

RedisClient.logger = ContextualLogger::LoggerWithContext.new(log_source: "redis_client", level: Logger::Severity::DEBUG)

Now the redis_client gem will be logging at the DEBUG level (regardless of logger's level) and all its log messages will be tagged with log_source = redis_client. With no changes required to the redis_client gem! :)

Factory shorthand for the above that snaps to the logger's level:

RedisClient.logger = ContextualLogger::LoggerWithContext.for_log_source: "redis_client")
  • Adds above class and factory.
  • Refactors ContextualLogger to have a LoggerMixin that implements the level and the debug, info...fatal methods so those can be used in both places.

@ColinDKelley ColinDKelley force-pushed the 2001/no-jira-passion-logger-with-context branch from 20c165b to 24df4fb Compare February 18, 2020 05:20

it "merges context" do
subject.fatal("fatal message", call_id: "234-123")
expect(log_stream.string).to match(/\{"message":"fatal message","severity":"FATAL","timestamp":".*","log_source":"redis_client","call_id":"234-123"\}/)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [157/150]

@ColinDKelley
Copy link
Contributor Author

@jebentier The contract change I mentioned on the screen share: 13bd8dd?utf8=%E2%9C%93&diff=split&w=1

require 'rubygems'
require 'bundler/setup'


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLines: Extra blank line detected.

@@ -0,0 +1,14 @@
#!/usr/bin/env rake

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/ScriptPermission: Script file Rakefile doesn't have execute permission.

@ColinDKelley
Copy link
Contributor Author

@jebentier Can you please review the changes I just pushed?

@ColinDKelley ColinDKelley merged commit 5734bd3 into master Mar 2, 2020
@ColinDKelley ColinDKelley deleted the 2001/no-jira-passion-logger-with-context branch March 2, 2020 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants