Skip to content

Commit

Permalink
Add support for replacing Rails logger (#45)
Browse files Browse the repository at this point in the history
* Add support for silencer

* Add documentation

* Update version

* Update Gemfile.lock
  • Loading branch information
dickdavis authored Oct 14, 2023
1 parent 37ac68f commit 6f3475c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0]
## [0.3.1] - 2023-10-14

### Added

- Added support for using `EventLoggerRails::JsonLogger` as a Rails logger replacement.

## [0.3.0] - 2023-10-05

### Added

Expand Down Expand Up @@ -64,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release

[Unreleased]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.0...HEAD
[Unreleased]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.1...HEAD
[0.3.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.2.1...0.3.0
[0.2.1]: https://github.com/d3d1rty/event_logger_rails/compare/0.2.0...0.2.1
[0.2.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.1.0...0.2.0
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
event_logger_rails (0.3.0)
event_logger_rails (0.3.1)
rails (>= 7.0.0)

GEM
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ Rails.application.configure do |config|
end
```

You can also configure the Rails logger to use `EventLoggerRails::JsonLogger` to render structured logs in JSON format with the additional app and request data.

```ruby
Rails.application.configure do
config.colorize_logging = false
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', :info)
logger = EventLoggerRails::JsonLogger.new($stdout)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
```

## Contributing

Your inputs echo in this realm. Venture forth and materialize your thoughts through a PR.
Expand Down
2 changes: 2 additions & 0 deletions lib/event_logger_rails/json_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module EventLoggerRails
##
# Writes log entries in JSON format
class JsonLogger < ::Logger
include ActiveSupport::LoggerSilence

def initialize(...)
super(...)
@formatter = proc do |level, timestamp, _progname, message|
Expand Down
2 changes: 1 addition & 1 deletion lib/event_logger_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module EventLoggerRails
VERSION = '0.3.0'
VERSION = '0.3.1'
end

0 comments on commit 6f3475c

Please sign in to comment.