semantic_logger_datadog 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 601074c776382fb609d87e888c959a6d9ca99d300a651ab8ac8d68790a4d293e
4
- data.tar.gz: 340850a4ddd2c82b54e15256b838d782c4869bcbf37974faf3e0ca8b6e654ac4
3
+ metadata.gz: 2025f51dda770776569afc5db87ded32b635dc0754070cfddbe1f471bcb6eb4c
4
+ data.tar.gz: 86dcb7f5a2bb59d130e07e314c7b9bbfa5faa2343a079e39ebedd1190e760ba7
5
5
  SHA512:
6
- metadata.gz: 2544b4d572b362228616146daeaf98d9eb598cbfbb0544455c43d2059b85793f0dedbd075d425357a45010a7a433eec1d2cae8026c049ce2e821305712bee56a
7
- data.tar.gz: 5c2ad0dbac03147d1784ccee0c3e1783fb498b4b604814fecd3600e51e535d45f942b38c5f63c8574f746ef93efd4df68636049c1d32c07aa242ef87c92939c1
6
+ metadata.gz: 5d9074ab8f9bcb59a4ac1285dd95c400e035dfcbfd315496354a31e05881b898103131fb837dd058af3d2184dd3548c8fe741b8383997099d4611c62f1c40abb
7
+ data.tar.gz: 324d9f5afcf7b3f3022462a4a17bac09cb83fd7df1f6df4127d24d1c98155186b76033bd5191fcf6ee88970c298dcceaa7dff8a717899711cf904a5186899f2a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # semantic_logger_datadog
2
2
 
3
- **[Semantic Logger](https://logger.rocketjob.io) formatter for submitting JSON logs to [Datadog](https://www.datadoghq.com).**
3
+ **[Semantic Logger](https://logger.reidmorrison.com) formatter for submitting JSON logs to [Datadog](https://www.datadoghq.com).**
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/semantic_logger_datadog.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/semantic_logger_datadog)
6
6
  [![Downloads](https://img.shields.io/gem/dt/semantic_logger_datadog.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/semantic_logger_datadog)
@@ -22,7 +22,7 @@ require "semantic_logger_datadog"
22
22
  # Set the global default log level.
23
23
  SemanticLogger.default_level = :trace
24
24
 
25
- # Log to a file, and use the Datadog formatter.
25
+ # Log to a file and use the Datadog formatter.
26
26
  SemanticLogger.add_appender(file_name: "development.log", formatter: SemanticLoggerDatadog::Formatters::Json.new)
27
27
 
28
28
  # Create an instance of a logger and add the class name to every log message.
@@ -32,7 +32,7 @@ logger = SemanticLogger["MyClass"]
32
32
  logger.info "Hello, world!"
33
33
  ```
34
34
 
35
- Refer to [Semantic Logger's documentation](https://logger.rocketjob.io/customize.html) for more customization options.
35
+ Refer to [Semantic Logger's documentation](https://logger.reidmorrison.com/config.html) for more configuration options.
36
36
 
37
37
  ## Configuring Ruby on Rails
38
38
 
@@ -43,27 +43,11 @@ gem "rails_semantic_logger"
43
43
  gem "semantic_logger_datadog"
44
44
  ```
45
45
 
46
- Configure named tags in `config/application.rb`:
47
-
48
- ```ruby
49
- module App
50
- class Application < Rails::Application
51
- # Your app's existing configuration goes here…
52
-
53
- # Configure named tags to add to every log message.
54
- config.log_tags = {
55
- remote_ip: :remote_ip,
56
- request_id: :request_id,
57
- url: ->(request) { request.original_url },
58
- useragent: ->(request) { request.headers["user-agent"] },
59
- }
60
- end
61
- end
62
- ```
46
+ The included middleware configures relevant log tags using values provided by [Action Dispatch](https://api.rubyonrails.org/classes/ActionDispatch.html).
63
47
 
64
48
  ### Adding custom controller action data
65
49
 
66
- Optionally configure user-specific data in `app/controllers/application_controller.rb` by adding [an `append_info_to_payload` method](https://logger.rocketjob.io/rails.html#adding-custom-data-to-the-rails-completed-log-message):
50
+ Optionally configure user-specific data in `app/controllers/application_controller.rb` by adding [an `append_info_to_payload` method](https://logger.reidmorrison.com/rails.html#add-custom-data-to-the-completed-message):
67
51
 
68
52
  ```ruby
69
53
  def append_info_to_payload(payload)
@@ -7,9 +7,18 @@ module SemanticLoggerDatadog
7
7
  super
8
8
  end
9
9
 
10
+ # Returns log messages in JSON format.
11
+ #
10
12
  # @return [String]
11
13
  def call(*)
12
- super.to_json
14
+ SemanticLogger::Utils.to_json(super)
15
+ end
16
+
17
+ # Returns a batch of log messages as a JSON array.
18
+ #
19
+ # @return [String]
20
+ def batch(logs, logger)
21
+ "[#{logs.map { |log| call(log, logger) }.join(",")}]"
13
22
  end
14
23
  end
15
24
  end
@@ -3,6 +3,8 @@
3
3
  module SemanticLoggerDatadog
4
4
  module Formatters
5
5
  class Raw < SemanticLogger::Formatters::Raw
6
+ # Returns log messages in Hash format.
7
+ #
6
8
  # @return [Hash]
7
9
  def call(*)
8
10
  super
@@ -66,7 +68,7 @@ module SemanticLoggerDatadog
66
68
 
67
69
  # Don't log process ID.
68
70
  #
69
- # @see https://logger.rocketjob.io/customize.html#example-do-not-log-the-process-id
71
+ # @see https://logger.reidmorrison.com/config.html#:~:text=A%20common%20request%20is%20to%20leave%20out%20the%20process%20id
70
72
  #
71
73
  # @return [nil]
72
74
  def pid
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticLoggerDatadog
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ request = ActionDispatch::Request.new(env)
11
+
12
+ hash = {
13
+ remote_ip: request.remote_ip,
14
+ request_id: request.request_id,
15
+ url: request.original_url,
16
+ useragent: request.headers["user-agent"],
17
+ }
18
+
19
+ SemanticLogger.named_tagged(hash) { @app.call(env) }
20
+ end
21
+ end
22
+ end
@@ -6,30 +6,30 @@ rescue LoadError => e
6
6
  raise %(semantic_logger_datadog: Install the rails_semantic_logger gem to continue. (#{e}))
7
7
  end
8
8
 
9
+ require_relative "middleware"
10
+
9
11
  module SemanticLoggerDatadog
10
12
  class Railtie < Rails::Railtie
13
+ # Log to standard output when +RAILS_LOG_TO_STDOUT+ is configured.
14
+ #
15
+ # @see https://logger.reidmorrison.com/rails.html#output-formats
16
+ # @see https://logger.reidmorrison.com/rails.html#production-on-a-container-platform-docker-kubernetes-heroku
17
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
18
+ config.rails_semantic_logger.appenders do |appenders|
19
+ appenders.add(formatter: SemanticLoggerDatadog::Formatters::Json.new, io: $stdout)
20
+ end
21
+ end
22
+
11
23
  initializer "semantic_logger_datadog.configure_rails_initialization" do |app|
12
24
  # Set application name.
13
25
  app.config.semantic_logger.application = Rails.application.name
14
26
 
15
27
  # Set backtrace level to avoid memory leaks due to high object allocation.
16
28
  #
17
- # @see https://logger.rocketjob.io/rails.html#include-the-file-name-and-line-number-in-the-source-code-where-the-message-originated
29
+ # @see https://logger.reidmorrison.com/rails.html#source-file-name-and-line-number
18
30
  app.config.semantic_logger.backtrace_level = :error if Rails.env.production?
19
31
 
20
- # Set log output format.
21
- #
22
- # @see https://logger.rocketjob.io/rails.html#output-format
23
- app.config.rails_semantic_logger.format = SemanticLoggerDatadog::Formatters::Json.new
24
-
25
- # Log to standard output when +RAILS_LOG_TO_STDOUT+ is configured.
26
- #
27
- # @see https://logger.rocketjob.io/rails.html#log-to-standard-out
28
- if ENV["RAILS_LOG_TO_STDOUT"].present?
29
- $stdout.sync = true
30
- app.config.rails_semantic_logger.add_file_appender = false
31
- app.config.semantic_logger.add_appender(formatter: app.config.rails_semantic_logger.format, io: $stdout)
32
- end
32
+ app.middleware.insert_before RailsSemanticLogger::Rack::Logger, SemanticLoggerDatadog::Middleware
33
33
  end
34
34
  end
35
35
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.required_ruby_version = ">= 3.1"
4
+ spec.required_ruby_version = ">= 3.2"
5
5
 
6
6
  spec.name = "semantic_logger_datadog"
7
- spec.version = "0.1.0"
7
+ spec.version = "1.0.0"
8
8
  spec.authors = ["CargoSense"]
9
9
  spec.email = ["rubygems@cargosense.com"]
10
10
 
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  "source_code_uri" => "#{spec.homepage}/tree/v#{spec.version}",
29
29
  }
30
30
 
31
- spec.add_dependency "semantic_logger", "~> 4.17"
31
+ spec.add_dependency "semantic_logger", "~> 5.1"
32
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger_datadog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CargoSense
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '4.17'
18
+ version: '5.1'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '4.17'
25
+ version: '5.1'
26
26
  description: Semantic Logger formatter for submitting JSON logs to Datadog.
27
27
  email:
28
28
  - rubygems@cargosense.com
@@ -35,6 +35,7 @@ files:
35
35
  - lib/semantic_logger_datadog.rb
36
36
  - lib/semantic_logger_datadog/formatters/json.rb
37
37
  - lib/semantic_logger_datadog/formatters/raw.rb
38
+ - lib/semantic_logger_datadog/middleware.rb
38
39
  - lib/semantic_logger_datadog/railtie.rb
39
40
  - semantic_logger_datadog.gemspec
40
41
  homepage: https://github.com/CargoSense/semantic_logger_datadog
@@ -43,10 +44,10 @@ licenses:
43
44
  metadata:
44
45
  bug_tracker_uri: https://github.com/CargoSense/semantic_logger_datadog/issues
45
46
  changelog_uri: https://github.com/CargoSense/semantic_logger_datadog/releases
46
- documentation_uri: https://rubydoc.info/gems/semantic_logger_datadog/0.1.0
47
+ documentation_uri: https://rubydoc.info/gems/semantic_logger_datadog/1.0.0
47
48
  homepage_uri: https://github.com/CargoSense/semantic_logger_datadog
48
49
  rubygems_mfa_required: 'true'
49
- source_code_uri: https://github.com/CargoSense/semantic_logger_datadog/tree/v0.1.0
50
+ source_code_uri: https://github.com/CargoSense/semantic_logger_datadog/tree/v1.0.0
50
51
  rdoc_options: []
51
52
  require_paths:
52
53
  - lib
@@ -54,14 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
55
  requirements:
55
56
  - - ">="
56
57
  - !ruby/object:Gem::Version
57
- version: '3.1'
58
+ version: '3.2'
58
59
  required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  requirements:
60
61
  - - ">="
61
62
  - !ruby/object:Gem::Version
62
63
  version: '0'
63
64
  requirements: []
64
- rubygems_version: 3.7.2
65
+ rubygems_version: 4.0.21
65
66
  specification_version: 4
66
67
  summary: Semantic Logger formatter for submitting JSON logs to Datadog.
67
68
  test_files: []