inst-wide-logger 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +10 -0
- data/README.md +50 -0
- data/Rakefile +8 -0
- data/lib/wide_logger/dev_json_formatter.rb +15 -0
- data/lib/wide_logger/version.rb +5 -0
- data/lib/wide_logger/wide_logger.rb +44 -0
- data/lib/wide_logger.rb +6 -0
- data/wide_logger.gemspec +30 -0
- metadata +70 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e8396c15e0ed6c58c85344244cd56f9495d7ed8ed509d287f72af53e64793112
|
|
4
|
+
data.tar.gz: 3acb7318de4dfd72a9b01aee71b01074158805fe7a792866448e56ee935105d6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: eea5cd1bd0a1ecb737a05489f226d9ea13008b0573b27301bfec3e99172ccb650fd26ad5f89f137246f1123730bd41e834c0c84169d6e848b63a1616bf00bab4
|
|
7
|
+
data.tar.gz: 70e8bc59cb5d2b2645b47150c43c1ff11e9c44c36cfbc2e468dc335a6313741ee8438e194d90a7e7a801b27c2f426b6241366420150680dbe08576c8468fb99e
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.0.0] - 2026-04-01
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `WideLogger.wrap` for wrapping code blocks with structured wide logging
|
|
8
|
+
- `WideLogger.add_context` for adding metadata to the current logging context
|
|
9
|
+
- `WideLogger::DevJsonFormatter` for human-readable JSON log output in development
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# WideLogger
|
|
2
|
+
|
|
3
|
+
Instructure's implementation of
|
|
4
|
+
[Wide Logging](https://loggingsucks.com/) in New Quizzes.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
9
|
+
|
|
10
|
+
$ bundle add inst-wide-logger
|
|
11
|
+
|
|
12
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
13
|
+
|
|
14
|
+
$ gem install inst-wide-logger
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Add variables to the logging context:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
WideLogger.add_context({
|
|
22
|
+
user_id: current_user.id,
|
|
23
|
+
quiz_id: @quiz.id
|
|
24
|
+
})
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Wrapping a code block
|
|
28
|
+
This will create a log entry at the end of the block with the context variables. If error is raised, the log entry will be created with the error information.
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
WideLogger.wrap(type: :web_request, metadata: { additional_context: @context }) do
|
|
32
|
+
# code to execute
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Optionally, you can use WideLogger:DevJsonFormatter to have log entries in the following format:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
<timestamp> <message> <context in JSON format>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
|
|
45
|
+
|
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
47
|
+
|
|
48
|
+
## Contributing
|
|
49
|
+
|
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/instructure-internal/wide-logger
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WideLogger
|
|
4
|
+
class DevJsonFormatter < PaulBunyan::JSONFormatter
|
|
5
|
+
def call(severity, time, progname, msg)
|
|
6
|
+
time.utc.strftime(DATETIME_FORMAT) + ' ' + msg.to_s + ' ' + super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def merge_metadata_and_message(metadata, message)
|
|
12
|
+
super.except('message', 'ts').sort_by { |key, _| key.to_s }.to_h
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WideLogger
|
|
4
|
+
EVENT_TYPES = {
|
|
5
|
+
web_request: 'canonical_request_summary',
|
|
6
|
+
job: 'canonical_job_summary',
|
|
7
|
+
sqs: 'canonical_sqs_summary'
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def wrap(type:, metadata: {})
|
|
12
|
+
event_type = EVENT_TYPES.fetch(type)
|
|
13
|
+
|
|
14
|
+
Rails.logger.add_metadata(
|
|
15
|
+
log_event_type: event_type,
|
|
16
|
+
**metadata
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
result = yield
|
|
20
|
+
|
|
21
|
+
emit_event(event_type)
|
|
22
|
+
result
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
emit_event(event_type, e)
|
|
25
|
+
raise
|
|
26
|
+
ensure
|
|
27
|
+
Rails.logger.clear_metadata!
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_context(context = {}, **kw_context)
|
|
31
|
+
Rails.logger.add_metadata(context, **kw_context)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def emit_event(event_type, e = nil)
|
|
37
|
+
if e
|
|
38
|
+
Rails.logger.error("#{event_type} failed with error: #{e.message}")
|
|
39
|
+
else
|
|
40
|
+
Rails.logger.info(event_type)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/wide_logger.rb
ADDED
data/wide_logger.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/wide_logger/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'inst-wide-logger'
|
|
7
|
+
spec.version = WideLogger::VERSION
|
|
8
|
+
spec.authors = ['Zoltan Hegedus']
|
|
9
|
+
spec.email = ['zoltan.hegedus@instructure.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Wide logging with structured metadata for Rails applications'
|
|
12
|
+
spec.homepage = 'https://github.com/instructure-internal/wide-logger'
|
|
13
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
14
|
+
|
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
19
|
+
|
|
20
|
+
spec.files = Dir.chdir(__dir__) do
|
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
22
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git))})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = 'exe'
|
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ['lib']
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'paul_bunyan', '~> 2.1'
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: inst-wide-logger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Zoltan Hegedus
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-04-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: paul_bunyan
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.1'
|
|
27
|
+
description:
|
|
28
|
+
email:
|
|
29
|
+
- zoltan.hegedus@instructure.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".rspec"
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- Gemfile
|
|
37
|
+
- README.md
|
|
38
|
+
- Rakefile
|
|
39
|
+
- lib/wide_logger.rb
|
|
40
|
+
- lib/wide_logger/dev_json_formatter.rb
|
|
41
|
+
- lib/wide_logger/version.rb
|
|
42
|
+
- lib/wide_logger/wide_logger.rb
|
|
43
|
+
- wide_logger.gemspec
|
|
44
|
+
homepage: https://github.com/instructure-internal/wide-logger
|
|
45
|
+
licenses: []
|
|
46
|
+
metadata:
|
|
47
|
+
allowed_push_host: https://rubygems.org
|
|
48
|
+
homepage_uri: https://github.com/instructure-internal/wide-logger
|
|
49
|
+
source_code_uri: https://github.com/instructure-internal/wide-logger
|
|
50
|
+
rubygems_mfa_required: 'true'
|
|
51
|
+
post_install_message:
|
|
52
|
+
rdoc_options: []
|
|
53
|
+
require_paths:
|
|
54
|
+
- lib
|
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 3.1.0
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0'
|
|
65
|
+
requirements: []
|
|
66
|
+
rubygems_version: 3.3.27
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 4
|
|
69
|
+
summary: Wide logging with structured metadata for Rails applications
|
|
70
|
+
test_files: []
|