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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -81
  3. data/Rakefile +39 -3
  4. data/docs/api.md +480 -0
  5. data/docs/appenders.md +990 -0
  6. data/docs/config.md +605 -0
  7. data/docs/index.md +197 -0
  8. data/docs/log.md +108 -0
  9. data/docs/metrics.md +168 -0
  10. data/docs/operations.md +400 -0
  11. data/docs/rails.md +816 -0
  12. data/docs/security.md +119 -0
  13. data/docs/testing.md +285 -0
  14. data/docs/upgrading.md +409 -0
  15. data/lib/semantic_logger/appender/async.rb +86 -173
  16. data/lib/semantic_logger/appender/cloudwatch_logs.rb +8 -6
  17. data/lib/semantic_logger/appender/elasticsearch.rb +8 -187
  18. data/lib/semantic_logger/appender/elasticsearch_base.rb +212 -0
  19. data/lib/semantic_logger/appender/elasticsearch_http.rb +16 -9
  20. data/lib/semantic_logger/appender/file.rb +25 -4
  21. data/lib/semantic_logger/appender/graylog.rb +2 -2
  22. data/lib/semantic_logger/appender/http.rb +27 -2
  23. data/lib/semantic_logger/appender/io.rb +8 -4
  24. data/lib/semantic_logger/appender/kafka.rb +2 -2
  25. data/lib/semantic_logger/appender/loki.rb +2 -4
  26. data/lib/semantic_logger/appender/mongodb.rb +3 -6
  27. data/lib/semantic_logger/appender/new_relic.rb +6 -0
  28. data/lib/semantic_logger/appender/new_relic_logs.rb +4 -3
  29. data/lib/semantic_logger/appender/open_telemetry.rb +10 -7
  30. data/lib/semantic_logger/appender/opensearch.rb +36 -0
  31. data/lib/semantic_logger/appender/rabbitmq.rb +5 -4
  32. data/lib/semantic_logger/appender/sentry.rb +5 -0
  33. data/lib/semantic_logger/appender/sentry_ruby.rb +2 -2
  34. data/lib/semantic_logger/appender/splunk.rb +2 -2
  35. data/lib/semantic_logger/appender/splunk_http.rb +3 -3
  36. data/lib/semantic_logger/appender/syslog.rb +11 -7
  37. data/lib/semantic_logger/appender/tcp.rb +4 -3
  38. data/lib/semantic_logger/appender/udp.rb +2 -2
  39. data/lib/semantic_logger/appender/wrapper.rb +5 -4
  40. data/lib/semantic_logger/appender.rb +36 -22
  41. data/lib/semantic_logger/appenders.rb +27 -5
  42. data/lib/semantic_logger/base.rb +100 -23
  43. data/lib/semantic_logger/concerns/compatibility.rb +2 -2
  44. data/lib/semantic_logger/core_ext/process.rb +34 -0
  45. data/lib/semantic_logger/formatters/base.rb +46 -7
  46. data/lib/semantic_logger/formatters/color.rb +9 -3
  47. data/lib/semantic_logger/formatters/default.rb +11 -4
  48. data/lib/semantic_logger/formatters/ecs.rb +151 -0
  49. data/lib/semantic_logger/formatters/fluentd.rb +15 -4
  50. data/lib/semantic_logger/formatters/json.rb +6 -1
  51. data/lib/semantic_logger/formatters/logfmt.rb +6 -4
  52. data/lib/semantic_logger/formatters/loki.rb +4 -4
  53. data/lib/semantic_logger/formatters/open_telemetry.rb +15 -5
  54. data/lib/semantic_logger/formatters/pattern.rb +237 -0
  55. data/lib/semantic_logger/formatters/raw.rb +2 -2
  56. data/lib/semantic_logger/formatters/signalfx.rb +2 -2
  57. data/lib/semantic_logger/formatters/syslog.rb +16 -4
  58. data/lib/semantic_logger/formatters/syslog_cee.rb +3 -2
  59. data/lib/semantic_logger/formatters.rb +2 -0
  60. data/lib/semantic_logger/log.rb +18 -4
  61. data/lib/semantic_logger/logger.rb +2 -2
  62. data/lib/semantic_logger/metric/new_relic.rb +2 -2
  63. data/lib/semantic_logger/metric/signalfx.rb +6 -4
  64. data/lib/semantic_logger/metric/statsd.rb +2 -2
  65. data/lib/semantic_logger/processor.rb +21 -0
  66. data/lib/semantic_logger/queue_processor.rb +372 -0
  67. data/lib/semantic_logger/reporters/minitest.rb +8 -8
  68. data/lib/semantic_logger/semantic_logger.rb +103 -11
  69. data/lib/semantic_logger/subscriber.rb +15 -2
  70. data/lib/semantic_logger/sync_processor.rb +25 -3
  71. data/lib/semantic_logger/test/capture_log_events.rb +3 -3
  72. data/lib/semantic_logger/test/minitest.rb +8 -4
  73. data/lib/semantic_logger/test/rspec.rb +249 -0
  74. data/lib/semantic_logger/utils.rb +83 -4
  75. data/lib/semantic_logger/version.rb +1 -1
  76. data/lib/semantic_logger.rb +9 -0
  77. metadata +28 -8
  78. 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: 98c3a3e01f125e81eb58559ca0f7931c55bb787102d89d0c10dd9c9a7ea2e221
4
- data.tar.gz: 8d82c20b77fe2c98773b72ab2483bdfb2d1267c65f9b8102cb2ffba00c141ee9
3
+ metadata.gz: f18701015c0b556099814aff1b79e251df13f556c103a8366b58357d9d10fd8c
4
+ data.tar.gz: cf18f050902946ac09a065a52a6f4cee9841f5c250ef30162d39347977e071d2
5
5
  SHA512:
6
- metadata.gz: c014af737549553d82d1d65ac1f46fbb09cefae9cb5aca3d5c39a4bbc180587fea4a65fa6756cad87eb031af52806693ddf11b9c2a4564bb140b1b1261b216c7
7
- data.tar.gz: f0c050cb59d1a3022fbf2b5ca180b644493c8630103e09498e7a9097bbda97df3cb3a28b84f125331196819123cad128f85a142c7952918d9df376acfd1dff69
6
+ metadata.gz: f62d59fc517122f6da01702c62cf5a33e47d629605f0dd5e096f953ebdcd7d3e6dbb9bf2e25d166d32f171dbe16ba1470726ebe760343e6e04994cef7b5c6dcd
7
+ data.tar.gz: 3c741614f72b723e50ed3e3ec2a785de85eb6a026b9ed52d67bb064c1617814d77afeb67e5f8f7f4cb6f20f339affd14f54a82ffe23194e256ba66da9e8aedf0
data/README.md CHANGED
@@ -1,13 +1,50 @@
1
1
  # Semantic Logger
2
2
  [![Gem Version](https://img.shields.io/gem/v/semantic_logger.svg)](https://rubygems.org/gems/semantic_logger) [![Build Status](https://github.com/reidmorrison/semantic_logger/workflows/build/badge.svg)](https://github.com/reidmorrison/semantic_logger/actions?query=workflow%3Abuild) [![Downloads](https://img.shields.io/gem/dt/semantic_logger.svg)](https://rubygems.org/gems/semantic_logger) [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](http://opensource.org/licenses/Apache-2.0) ![](https://img.shields.io/badge/status-Production%20Ready-blue.svg)
3
3
 
4
- Semantic Logger is a feature rich logging framework, and replacement for existing Ruby & Rails loggers.
4
+ Semantic Logger is a high-performance, asynchronous structured logging framework for Ruby
5
+ and Rails.
5
6
 
6
- * https://logger.rocketjob.io/
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
- [Semantic Logger Guide](https://logger.rocketjob.io/)
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 to Semantic Logger v4.9
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
- Additionally, this needs to be changed from:
90
- ~~~ruby
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
- # system "git tag -a v#{SemanticLogger::VERSION} -m 'Tagging #{SemanticLogger::VERSION}'"
13
- # system "git push --tags"
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
- task default: :test
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]