semantic_logger 4.18.0 → 5.1.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 +4 -4
- data/README.md +51 -81
- data/Rakefile +39 -3
- data/docs/api.md +480 -0
- data/docs/appenders.md +990 -0
- data/docs/config.md +605 -0
- data/docs/index.md +197 -0
- data/docs/log.md +108 -0
- data/docs/metrics.md +168 -0
- data/docs/operations.md +400 -0
- data/docs/rails.md +816 -0
- data/docs/security.md +119 -0
- data/docs/testing.md +285 -0
- data/docs/upgrading.md +409 -0
- data/lib/semantic_logger/appender/async.rb +86 -173
- data/lib/semantic_logger/appender/cloudwatch_logs.rb +8 -6
- data/lib/semantic_logger/appender/elasticsearch.rb +8 -187
- data/lib/semantic_logger/appender/elasticsearch_base.rb +212 -0
- data/lib/semantic_logger/appender/elasticsearch_http.rb +16 -9
- data/lib/semantic_logger/appender/file.rb +25 -4
- data/lib/semantic_logger/appender/graylog.rb +2 -2
- data/lib/semantic_logger/appender/http.rb +27 -2
- data/lib/semantic_logger/appender/io.rb +8 -4
- data/lib/semantic_logger/appender/kafka.rb +2 -2
- data/lib/semantic_logger/appender/loki.rb +2 -4
- data/lib/semantic_logger/appender/mongodb.rb +3 -6
- data/lib/semantic_logger/appender/new_relic.rb +6 -0
- data/lib/semantic_logger/appender/new_relic_logs.rb +4 -3
- data/lib/semantic_logger/appender/open_telemetry.rb +10 -7
- data/lib/semantic_logger/appender/opensearch.rb +36 -0
- data/lib/semantic_logger/appender/rabbitmq.rb +5 -4
- data/lib/semantic_logger/appender/sentry.rb +5 -0
- data/lib/semantic_logger/appender/sentry_ruby.rb +2 -2
- data/lib/semantic_logger/appender/splunk.rb +2 -2
- data/lib/semantic_logger/appender/splunk_http.rb +3 -3
- data/lib/semantic_logger/appender/syslog.rb +11 -7
- data/lib/semantic_logger/appender/tcp.rb +4 -3
- data/lib/semantic_logger/appender/udp.rb +2 -2
- data/lib/semantic_logger/appender/wrapper.rb +5 -4
- data/lib/semantic_logger/appender.rb +36 -22
- data/lib/semantic_logger/appenders.rb +27 -5
- data/lib/semantic_logger/base.rb +100 -23
- data/lib/semantic_logger/concerns/compatibility.rb +2 -2
- data/lib/semantic_logger/core_ext/process.rb +34 -0
- data/lib/semantic_logger/formatters/base.rb +46 -7
- data/lib/semantic_logger/formatters/color.rb +9 -3
- data/lib/semantic_logger/formatters/default.rb +11 -4
- data/lib/semantic_logger/formatters/ecs.rb +151 -0
- data/lib/semantic_logger/formatters/fluentd.rb +15 -4
- data/lib/semantic_logger/formatters/json.rb +6 -1
- data/lib/semantic_logger/formatters/logfmt.rb +6 -4
- data/lib/semantic_logger/formatters/loki.rb +4 -4
- data/lib/semantic_logger/formatters/open_telemetry.rb +15 -5
- data/lib/semantic_logger/formatters/pattern.rb +237 -0
- data/lib/semantic_logger/formatters/raw.rb +2 -2
- data/lib/semantic_logger/formatters/signalfx.rb +2 -2
- data/lib/semantic_logger/formatters/syslog.rb +16 -4
- data/lib/semantic_logger/formatters/syslog_cee.rb +3 -2
- data/lib/semantic_logger/formatters.rb +2 -0
- data/lib/semantic_logger/log.rb +18 -4
- data/lib/semantic_logger/logger.rb +2 -2
- data/lib/semantic_logger/metric/new_relic.rb +2 -2
- data/lib/semantic_logger/metric/signalfx.rb +6 -4
- data/lib/semantic_logger/metric/statsd.rb +2 -2
- data/lib/semantic_logger/processor.rb +21 -0
- data/lib/semantic_logger/queue_processor.rb +372 -0
- data/lib/semantic_logger/reporters/minitest.rb +8 -8
- data/lib/semantic_logger/semantic_logger.rb +103 -11
- data/lib/semantic_logger/subscriber.rb +15 -2
- data/lib/semantic_logger/sync_processor.rb +25 -3
- data/lib/semantic_logger/test/capture_log_events.rb +3 -3
- data/lib/semantic_logger/test/minitest.rb +8 -4
- data/lib/semantic_logger/test/rspec.rb +249 -0
- data/lib/semantic_logger/utils.rb +83 -4
- data/lib/semantic_logger/version.rb +1 -1
- data/lib/semantic_logger.rb +9 -0
- metadata +28 -8
- data/lib/semantic_logger/appender/async_batch.rb +0 -93
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f18701015c0b556099814aff1b79e251df13f556c103a8366b58357d9d10fd8c
|
|
4
|
+
data.tar.gz: cf18f050902946ac09a065a52a6f4cee9841f5c250ef30162d39347977e071d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f62d59fc517122f6da01702c62cf5a33e47d629605f0dd5e096f953ebdcd7d3e6dbb9bf2e25d166d32f171dbe16ba1470726ebe760343e6e04994cef7b5c6dcd
|
|
7
|
+
data.tar.gz: 3c741614f72b723e50ed3e3ec2a785de85eb6a026b9ed52d67bb064c1617814d77afeb67e5f8f7f4cb6f20f339affd14f54a82ffe23194e256ba66da9e8aedf0
|
data/README.md
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
# Semantic Logger
|
|
2
2
|
[](https://rubygems.org/gems/semantic_logger) [](https://github.com/reidmorrison/semantic_logger/actions?query=workflow%3Abuild) [](https://rubygems.org/gems/semantic_logger) [](http://opensource.org/licenses/Apache-2.0) 
|
|
3
3
|
|
|
4
|
-
Semantic Logger is a
|
|
4
|
+
Semantic Logger is a high-performance, asynchronous structured logging framework for Ruby
|
|
5
|
+
and Rails.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
It differs from ordinary loggers in two important ways:
|
|
8
|
+
|
|
9
|
+
1. **It logs structured data, not just strings.** Along with the text message, each log entry can
|
|
10
|
+
carry a payload (any Hash), an exception, a duration, metrics, and tags. That data is preserved
|
|
11
|
+
all the way to the destination, so it stays searchable instead of being flattened into text.
|
|
12
|
+
2. **It logs asynchronously.** Log events are pushed onto an in-memory queue and written to their
|
|
13
|
+
destinations by a separate background thread, so your application is not blocked while logs are
|
|
14
|
+
written. Semantic Logger can log thousands of lines per second without slowing the application
|
|
15
|
+
down.
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require "semantic_logger"
|
|
19
|
+
|
|
20
|
+
SemanticLogger.default_level = :info
|
|
21
|
+
SemanticLogger.add_appender(io: $stdout, formatter: :color)
|
|
22
|
+
|
|
23
|
+
logger = SemanticLogger["MyApp"]
|
|
24
|
+
|
|
25
|
+
# A plain message, plus structured data that stays searchable
|
|
26
|
+
logger.info("Queried users table", duration: 54, result: :ok, table: "users")
|
|
27
|
+
|
|
28
|
+
# Log an exception with its full backtrace, plus context
|
|
29
|
+
logger.error("Failed to process order", exception: exception, order_id: 42)
|
|
30
|
+
|
|
31
|
+
# Measure and log how long a block takes to run
|
|
32
|
+
logger.measure_info("Reindexing users") { reindex_users }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
When running Rails, use
|
|
36
|
+
[rails_semantic_logger](https://github.com/reidmorrison/rails_semantic_logger) instead, since it
|
|
37
|
+
replaces the Rails default logger with Semantic Logger automatically.
|
|
7
38
|
|
|
8
39
|
## Documentation
|
|
9
40
|
|
|
10
|
-
|
|
41
|
+
Start with the [Introduction](https://logger.rocketjob.io/), then the
|
|
42
|
+
[Programmer's Guide](https://logger.rocketjob.io/api.html).
|
|
43
|
+
|
|
44
|
+
* Full guide: [https://logger.rocketjob.io/](https://logger.rocketjob.io/)
|
|
45
|
+
* For AI assistants: [llms.txt](https://logger.rocketjob.io/llms.txt) (documentation index) and
|
|
46
|
+
[llms-full.txt](https://logger.rocketjob.io/llms-full.txt) (complete documentation in one file).
|
|
47
|
+
The same pages are also included as markdown in the installed gem, under `docs/`.
|
|
11
48
|
|
|
12
49
|
## Logging Destinations
|
|
13
50
|
|
|
@@ -28,6 +65,7 @@ Logging to the following destinations are all supported "out-of-the-box":
|
|
|
28
65
|
* UDP
|
|
29
66
|
* Syslog
|
|
30
67
|
* CloudWatch Logs
|
|
68
|
+
* OpenTelemetry
|
|
31
69
|
* Add any existing Ruby logger as another destination.
|
|
32
70
|
* Roll-your-own
|
|
33
71
|
|
|
@@ -63,89 +101,16 @@ and are therefore not automatically included by this gem:
|
|
|
63
101
|
- Syslog Appender to a remote syslogng server over TCP or UDP: gem 'net_tcp_client'
|
|
64
102
|
- Splunk Appender: gem 'splunk-sdk-ruby'
|
|
65
103
|
- Elasticsearch Appender: gem 'elasticsearch'
|
|
104
|
+
- OpenSearch Appender: gem 'opensearch-ruby'
|
|
66
105
|
- Kafka Appender: gem 'ruby-kafka'
|
|
67
106
|
- Legacy Sentry Appender: gem 'sentry-raven' (deprecated)
|
|
68
107
|
- Sentry Appender: gem 'sentry-ruby'
|
|
108
|
+
- OpenTelemetry Appender: gem 'opentelemetry-logs-sdk' (plus an exporter, e.g. 'opentelemetry-exporter-otlp-logs')
|
|
69
109
|
|
|
70
|
-
## Upgrading
|
|
71
|
-
|
|
72
|
-
These changes should not be noticeable by the majority of users of Semantic Logger, since
|
|
73
|
-
they are to the internal API. It is possible that advanced users may be using these internal
|
|
74
|
-
API's directly.
|
|
75
|
-
|
|
76
|
-
This does not affect any calls to the public api `SemanticLogger.add_appender`.
|
|
77
|
-
|
|
78
|
-
File and IO are now separate appenders. When creating the File appender explicitly, its arguments
|
|
79
|
-
have changed. For example, when requesting an IO stream, it needs to be changed from:
|
|
80
|
-
|
|
81
|
-
~~~ruby
|
|
82
|
-
SemanticLogger::Appender::File.new(io: $stderr)
|
|
83
|
-
~~~
|
|
84
|
-
to:
|
|
85
|
-
~~~ruby
|
|
86
|
-
SemanticLogger::Appender::IO.new($stderr)
|
|
87
|
-
~~~
|
|
110
|
+
## Upgrading
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
SemanticLogger::Appender::File.new(file_name: "file.log")
|
|
92
|
-
~~~
|
|
93
|
-
to:
|
|
94
|
-
~~~ruby
|
|
95
|
-
SemanticLogger::Appender::File.new("file.log")
|
|
96
|
-
~~~
|
|
97
|
-
|
|
98
|
-
Rails Semantic Logger, if used, needs to be upgraded to v4.9 when upgrading to Semantic Logger v4.9.
|
|
99
|
-
|
|
100
|
-
## Upgrading to Semantic Logger v4.4
|
|
101
|
-
|
|
102
|
-
With some forking frameworks it is necessary to call `reopen` after the fork. With v4.4 the
|
|
103
|
-
workaround for Ruby 2.5 crashes is no longer needed.
|
|
104
|
-
I.e. Please remove the following line if being called anywhere:
|
|
105
|
-
|
|
106
|
-
~~~ruby
|
|
107
|
-
SemanticLogger::Processor.instance.instance_variable_set(:@queue, Queue.new)
|
|
108
|
-
~~~
|
|
109
|
-
|
|
110
|
-
## Upgrading to Semantic Logger v4.0
|
|
111
|
-
|
|
112
|
-
The following changes need to be made when upgrading to V4:
|
|
113
|
-
- Ruby V2.3 / JRuby V9.1 is now the minimum runtime version.
|
|
114
|
-
- Replace calls to Logger#with_payload with SemanticLogger.named_tagged.
|
|
115
|
-
- Replace calls to Logger#payload with SemanticLogger.named_tags.
|
|
116
|
-
- MongoDB Appender requires Mongo Ruby Client V2 or greater.
|
|
117
|
-
- Appenders now write payload data in a seperate :payload tag instead of mixing them
|
|
118
|
-
directly into the root elements to avoid name clashes.
|
|
119
|
-
|
|
120
|
-
As a result any calls like the following:
|
|
121
|
-
|
|
122
|
-
~~~ruby
|
|
123
|
-
logger.debug foo: 'foo', bar: 'bar'
|
|
124
|
-
~~~
|
|
125
|
-
|
|
126
|
-
Must be replaced with the following in v4:
|
|
127
|
-
|
|
128
|
-
~~~ruby
|
|
129
|
-
logger.debug payload: {foo: 'foo', bar: 'bar'}
|
|
130
|
-
~~~
|
|
131
|
-
|
|
132
|
-
Similarly, for measure blocks:
|
|
133
|
-
|
|
134
|
-
~~~ruby
|
|
135
|
-
logger.measure_info('How long is the sleep', foo: 'foo', bar: 'bar') { sleep 1 }
|
|
136
|
-
~~~
|
|
137
|
-
|
|
138
|
-
Must be replaced with the following in v4:
|
|
139
|
-
|
|
140
|
-
~~~ruby
|
|
141
|
-
logger.measure_info('How long is the sleep', payload: {foo: 'foo', bar: 'bar'}) { sleep 1 }
|
|
142
|
-
~~~
|
|
143
|
-
|
|
144
|
-
The common log call has not changed, and the payload is still logged directly:
|
|
145
|
-
|
|
146
|
-
~~~ruby
|
|
147
|
-
logger.debug('log this', foo: 'foo', bar: 'bar')
|
|
148
|
-
~~~
|
|
112
|
+
See the [Upgrading Guide](https://logger.rocketjob.io/upgrading.html) for instructions on
|
|
113
|
+
upgrading between major versions.
|
|
149
114
|
|
|
150
115
|
## Install
|
|
151
116
|
|
|
@@ -165,6 +130,11 @@ SemanticLogger.add_appender(file_name: 'development.log', formatter: :color)
|
|
|
165
130
|
|
|
166
131
|
If running rails, see: [Semantic Logger Rails](https://logger.rocketjob.io/rails.html)
|
|
167
132
|
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for how to set up the project, run the
|
|
136
|
+
tests, and an overview of the architecture, including a class diagram.
|
|
137
|
+
|
|
168
138
|
## Author
|
|
169
139
|
|
|
170
140
|
[Reid Morrison](https://github.com/reidmorrison)
|
data/Rakefile
CHANGED
|
@@ -4,21 +4,57 @@ require "rake/testtask"
|
|
|
4
4
|
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
|
5
5
|
require "semantic_logger/version"
|
|
6
6
|
|
|
7
|
+
desc "Build the semantic_logger gem"
|
|
7
8
|
task :gem do
|
|
8
9
|
system "gem build semantic_logger.gemspec"
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
desc "Tag and push the release, then publish the gem to RubyGems"
|
|
11
13
|
task publish: :gem do
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
system "git tag -a v#{SemanticLogger::VERSION} -m 'Tagging #{SemanticLogger::VERSION}'"
|
|
15
|
+
system "git push --tags"
|
|
14
16
|
system "gem push semantic_logger-#{SemanticLogger::VERSION}.gem"
|
|
15
17
|
system "rm semantic_logger-#{SemanticLogger::VERSION}.gem"
|
|
16
18
|
end
|
|
17
19
|
|
|
20
|
+
desc "Regenerate docs/llms-full.txt from the docs markdown pages"
|
|
21
|
+
task :llms_full do
|
|
22
|
+
pages = %w[index api config appenders log metrics rails testing operations security upgrading]
|
|
23
|
+
header = <<~HEADER
|
|
24
|
+
# Semantic Logger - Complete Documentation
|
|
25
|
+
|
|
26
|
+
> Semantic Logger is a high-performance, asynchronous structured logging framework for Ruby and Rails.
|
|
27
|
+
|
|
28
|
+
This file concatenates every page of https://logger.rocketjob.io for consumption by AI assistants.
|
|
29
|
+
It is generated from the markdown sources in docs/ by `bundle exec rake llms_full`; do not edit it directly.
|
|
30
|
+
A per-page index is available at https://logger.rocketjob.io/llms.txt
|
|
31
|
+
HEADER
|
|
32
|
+
|
|
33
|
+
sections = pages.map do |page|
|
|
34
|
+
text = File.read("docs/#{page}.md").
|
|
35
|
+
sub(/\A---\n.*?\n---\n/m, ""). # Jekyll front matter
|
|
36
|
+
gsub(/^\{:.*\}\n/, ""). # kramdown attribute lines ({:toc}, {:.no_toc}, ...)
|
|
37
|
+
gsub(/^\* TOC\n/, "").
|
|
38
|
+
gsub(/^\*\*Contents\*\*\n/, "").
|
|
39
|
+
gsub(/^!\[.*\n/, "") # images (relative paths, useless in plain text)
|
|
40
|
+
"<!-- source: docs/#{page}.md -->\n\n#{text.strip}\n"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
File.write("docs/llms-full.txt", ([header] + sections).join("\n\n---\n\n"))
|
|
44
|
+
puts "Wrote docs/llms-full.txt (#{File.size('docs/llms-full.txt')} bytes)"
|
|
45
|
+
end
|
|
46
|
+
|
|
18
47
|
Rake::TestTask.new(:test) do |t|
|
|
19
48
|
t.pattern = "test/**/*_test.rb"
|
|
20
49
|
t.verbose = true
|
|
21
50
|
t.warning = false
|
|
22
51
|
end
|
|
23
52
|
|
|
24
|
-
|
|
53
|
+
begin
|
|
54
|
+
require "rspec/core/rake_task"
|
|
55
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
56
|
+
rescue LoadError
|
|
57
|
+
# RSpec is only available in the test/development environment.
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
task default: %i[test spec]
|