Skip to content

Commit 8c0164d

Browse files
authored
Merge pull request #26 from on-strum/develop
OnStrum::Logs v1.0.0
2 parents 498a0c7 + e000777 commit 8c0164d

File tree

18 files changed

+113
-194
lines changed

18 files changed

+113
-194
lines changed

.circleci/gemspecs/latest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
2626
spec.add_development_dependency 'rake', '~> 13.1'
2727
spec.add_development_dependency 'reek', '~> 6.3'
2828
spec.add_development_dependency 'rspec', '~> 3.13'
29-
spec.add_development_dependency 'rubocop', '~> 1.61'
30-
spec.add_development_dependency 'rubocop-performance', '~> 1.20', '>= 1.20.2'
31-
spec.add_development_dependency 'rubocop-rspec', '~> 2.27', '>= 2.27.1'
29+
spec.add_development_dependency 'rubocop', '~> 1.62', '>= 1.62.1'
30+
spec.add_development_dependency 'rubocop-performance', '~> 1.21'
31+
spec.add_development_dependency 'rubocop-rspec', '~> 2.28'
3232
spec.add_development_dependency 'simplecov', '~> 0.22.0'
3333
end

.codeclimate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ checks:
99
plugins:
1010
rubocop:
1111
enabled: true
12-
channel: rubocop-1-61
12+
channel: rubocop-1-62
1313
config:
1414
file: .circleci/linter_configs/.rubocop.yml
1515

CHANGELOG.md

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,53 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [1.0.0] - 2024-03-31
6+
7+
### Added
8+
9+
- Added ability to define static fields in the logger document root
10+
11+
```ruby
12+
OnStrum::Logs.configure do |config|
13+
# Optional parameter. Ability to define static fields in the logger document root.
14+
# It is equal to empty hash by default.
15+
config.root_fields = {
16+
service_name: 'My Great Application',
17+
service_version: '1.42.0'
18+
}
19+
```
20+
21+
### Changed
22+
23+
- Changed `OnStrum::Logs.configure`, tests
24+
- Changed `OnStrum::Logs::Configuration`, tests
25+
- Changed `OnStrum::Logs::Logger::Default`, tests
26+
- Changed `OnStrum::Logs::RspecHelper::Configuration`, tests
27+
- Changed `OnStrum::Logs::RspecHelper::ContextGenerator`, tests
28+
- Changed RSpec helpers
29+
- Changed gem development dependencies
30+
- Changed gem documentation
31+
32+
### Removed
33+
34+
- Removed `service_name`, `service_version` required configuration options
35+
- Removed `OnStrum::Logs::RspecHelper::Configuration#complete?`
36+
537
## [0.3.0] - 2024-03-10
638

739
### Added
840

941
- Added ability to configure builtin attribute key names
1042

11-
### Updated
43+
### Changed
1244

13-
- Updated `OnStrum::Logs::Configuration`, tests
14-
- Updated `OnStrum::Logs::Logger::Default`, tests
15-
- Updated `OnStrum::Logs::Formatter::Base`, tests
16-
- Updated `OnStrum::Logs::Formatter::Json`, tests
17-
- Updated `OnStrum::Logs::RspecHelper::Configuration`, tests
18-
- Updated `OnStrum::Logs::RspecHelper::ContextGenerator`, tests
19-
- Updated gem documentation
45+
- Changed `OnStrum::Logs::Configuration`, tests
46+
- Changed `OnStrum::Logs::Logger::Default`, tests
47+
- Changed `OnStrum::Logs::Formatter::Base`, tests
48+
- Changed `OnStrum::Logs::Formatter::Json`, tests
49+
- Changed `OnStrum::Logs::RspecHelper::Configuration`, tests
50+
- Changed `OnStrum::Logs::RspecHelper::ContextGenerator`, tests
51+
- Changed gem documentation
2052

2153
## [0.2.0] - 2024-03-05
2254

@@ -25,23 +57,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2557
- Added Ruby 3.3 support
2658
- Added `commitspell` linter
2759

28-
### Updated
60+
### Changed
2961

30-
- Updated gem development dependencies
31-
- Updated gem documentation, license
62+
- Changed gem development dependencies
63+
- Changed gem documentation, license
3264

3365
## [0.1.1] - 2023-10-18
3466

3567
### Fixed
3668

3769
- Fixed gem class loading
3870

39-
### Updated
71+
### Changed
4072

41-
- Updated gem documentation
73+
- Changed gem documentation
4274

4375
## [0.1.0] - 2023-10-15
4476

4577
### Added
4678

47-
- First release of `on_strum-logs`.
79+
- Added first release of `on_strum-logs`.

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `on_strum-logs` - Simple structured logger
1+
# ![OnStrum::Logs - Simple configurable structured logger with JSON formatter out of the box](https://repository-images.githubusercontent.com/703974267/64869920-5005-490e-9e5d-90b49ba59f25)
22

33
[![Maintainability](https://api.codeclimate.com/v1/badges/2f4acd0ca4da58ca3b1e/maintainability)](https://codeclimate.com/github/on-strum/ruby-on-strum-logs/maintainability)
44
[![Test Coverage](https://api.codeclimate.com/v1/badges/2f4acd0ca4da58ca3b1e/test_coverage)](https://codeclimate.com/github/on-strum/ruby-on-strum-logs/test_coverage)
@@ -73,11 +73,12 @@ To start working with this gem, you must configure it first as in the example be
7373
require 'on_strum/logs'
7474

7575
OnStrum::Logs.configure do |config|
76-
# Required parameter. Current service name.
77-
config.service_name = 'My Great Application'
78-
79-
# Required parameter. Current service version.
80-
config.service_version = '1.42.0'
76+
# Optional parameter. Ability to define static fields in the logger document root.
77+
# It is equal to empty hash by default.
78+
config.root_fields = {
79+
service_name: 'My Great Application',
80+
service_version: '1.42.0'
81+
}
8182

8283
# Optional parameter. The colorized structured log in STDOUT. It could be useful
8384
# for debug mode.
@@ -211,8 +212,10 @@ For view detailed colorized logs you can use configuration option `detailed_form
211212
require 'on_strum/logs'
212213

213214
OnStrum::Logs.configure do |config|
214-
config.service_name = 'My Great Application'
215-
config.service_version = '1.42.0'
215+
config.root_fields = {
216+
service_name: 'My Great Application',
217+
service_version: '1.42.0'
218+
}
216219
config.detailed_formatter = true
217220
end
218221

lib/on_strum/logs.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ def configuration(&block)
99
@configuration ||= begin
1010
return unless block
1111

12-
configuration = OnStrum::Logs::Configuration.new(&block)
13-
raise OnStrum::Logs::Error::Configuration, OnStrum::Logs::Configuration::INCOMPLETE_CONFIG unless configuration.complete?
14-
15-
configuration
12+
OnStrum::Logs::Configuration.new(&block)
1613
end
1714
end
1815

lib/on_strum/logs/configuration.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
module OnStrum
44
module Logs
55
class Configuration
6-
INCOMPLETE_CONFIG = 'service_name, service_version are required parameters'
76
SETTERS = %i[
87
custom_formatter
9-
service_name
10-
service_version
8+
root_fields
119
field_name_level
1210
field_name_time
1311
field_name_message
@@ -32,26 +30,22 @@ def initialize(&block)
3230
end
3331
end
3432

35-
def complete?
36-
!!(service_name && service_version)
37-
end
38-
3933
def formatter
4034
custom_formatter || builded_formatter
4135
end
4236

43-
# TODO: hardcoded fields will be removed in next release
4437
def log_attributes_order
45-
@log_attributes_order ||= OnStrum::Logs::Configuration::SETTERS[3..6].map do |field_name_getter|
38+
@log_attributes_order ||= OnStrum::Logs::Configuration::SETTERS[2..5].map do |field_name_getter|
4639
public_send(field_name_getter)
47-
end + %i[service_name service_version]
40+
end + root_fields.keys
4841
end
4942

5043
private
5144

5245
def instance_initializer
5346
message_key = OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[2]
5447
{
48+
root_fields: {},
5549
field_name_level: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[0],
5650
field_name_time: OnStrum::Logs::Configuration::BUILTIN_FIELDS_DEFAULT_NAMES[1],
5751
field_name_message: message_key,
@@ -64,9 +58,9 @@ def instance_initializer
6458
def valid_argument_type?(method_name, argument)
6559
argument.is_a?(
6660
case method_name
67-
when :service_name, :service_version then ::String
68-
when *OnStrum::Logs::Configuration::SETTERS[3..-1] then ::Symbol
61+
when *OnStrum::Logs::Configuration::SETTERS[2..-1] then ::Symbol
6962
when :custom_formatter then ::Class
63+
when :root_fields then ::Hash
7064
end
7165
)
7266
end

lib/on_strum/logs/logger/default.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def formatter
3939
@formatter ||= proc do |_severity, datetime, _progname, log_data|
4040
configuration.formatter.call(
4141
configuration.field_name_time => datetime,
42-
service_name: configuration.service_name,
43-
service_version: configuration.service_version,
42+
**configuration.root_fields,
4443
**log_data
4544
)
4645
end

lib/on_strum/logs/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module OnStrum
44
module Logs
5-
VERSION = '0.3.0'
5+
VERSION = '1.0.0'
66
end
77
end

0 commit comments

Comments
 (0)