minato_logger 0.1.13.pre.2 → 0.1.13.pre.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b36cadb38deedc36c5e9f51e2f8924ec2232431a38665d6b4675d14444537f03
4
- data.tar.gz: adadd20e6af1782f4f10085d2fcc7974094ac8fcdb517c71d8ebecaedd967929
3
+ metadata.gz: 8912274da7dd77fae6f70e2236079b5ed24df2aef0326ef1cd0467aed0cd2dcc
4
+ data.tar.gz: 9fe88a71c8273fa4945b74d3d640761b6fc8bfb2c2bca0ae63e25cfb3b82fc2d
5
5
  SHA512:
6
- metadata.gz: b50dd26a5425582f4d5a720f4ac7215dfa30f83b801b597b428f11226dd1b226cf105c167df0c8b6dd770a30d1dd755727a4f1d1ca4e1125ce94e298c2dc1464
7
- data.tar.gz: 2d51f2816c59f2b6733dc86c14a6d811c524331b12c2adad8213de173e14d0eef1013c3f50d689e2a7d263dbd423bf5197cc94e97455f0180babf696cb39f606
6
+ metadata.gz: d7974899c02eee1e4f366b3391fbbb3c386dbbea2870ce4bc2f61396e4baf495c8b8bac7c32d9239e5b588e8646128e9a8b3f495c3897a5ce19592091a922ec7
7
+ data.tar.gz: 604ff2aabe0ee95c8f7f748026baa9b9abda1ad6bea00ac698550c686a6d4bc73d962902c30b2d77e0000e7f19f6b1e2e664d7535e46183c1712891ccd7107b6
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinatoLogger
4
+ class Configuration
5
+ attr_reader :middleware
6
+
7
+ def initialize
8
+ @middleware = MinatoLogger::Middleware.new
9
+
10
+ yield(self) if block_given?
11
+ end
12
+
13
+ def self.default
14
+ @default ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(self) if block_given?
19
+ end
20
+ end
21
+ end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/tagged_logging"
4
- require "json"
5
4
  require "google/cloud/trace"
6
- require "rails"
5
+ require "json"
7
6
 
8
7
  module MinatoLogger
9
8
  module Formatters
@@ -12,25 +11,19 @@ module MinatoLogger
12
11
 
13
12
  def call(severity, timestamp, _progname, message)
14
13
  log = add_message_to_logs({ severity: severity, time: timestamp }, message)
15
- log = add_trace_to_logs(log)
14
+ log = apply_middlewares(log)
16
15
 
17
16
  "#{log.to_json}\n"
18
17
  end
19
18
 
20
19
  private
21
20
 
22
- def add_trace_to_logs(log)
23
- return log unless ::Rails.env == "production"
24
-
25
- # Get Cloud Trace info to integrate with Cloud Logging
26
- _trace_client = Google::Cloud::Trace.new
27
- trace_result = Google::Cloud::Trace.get
28
- return log if trace_result.nil?
29
-
30
- trace_log = "projects/#{trace_result.trace.project_id}/traces/#{trace_result.trace.trace_id}"
21
+ def apply_middlewares(log)
22
+ MinatoLogger.config.middleware.middlewares.each do |middleware|
23
+ log = middleware.new.call(log)
24
+ end
31
25
 
32
- log.merge({ "logging.googleapis.com/trace": trace_log,
33
- "logging.googleapis.com/spanId": trace_result.span_id.to_s })
26
+ log
34
27
  end
35
28
 
36
29
  def add_message_to_logs(log, message)
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinatoLogger
4
+ class Middleware
5
+ attr_reader :middlewares
6
+
7
+ def initialize
8
+ @middlewares = []
9
+ end
10
+
11
+ def use(middleware)
12
+ @middlewares << middleware unless middleware.nil?
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module MinatoLogger
4
4
  class Railtie < ::Rails::Railtie
5
+ config.minato_logger = MinatoLogger::Configuration.default
6
+
5
7
  config.after_initialize do |app|
6
8
  app.config.colorize_logging = false if Rails.env.production?
7
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinatoLogger
4
- VERSION = "0.1.13-2"
4
+ VERSION = "0.1.13-4"
5
5
  end
data/lib/minato_logger.rb CHANGED
@@ -1,6 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "minato_logger/version"
4
- require_relative "minato_logger/formatters"
5
- require_relative "minato_logger/logger"
6
- require_relative "minato_logger/rails" if defined?(Rails)
3
+ require "minato_logger/version"
4
+ require "minato_logger/middleware"
5
+ require "minato_logger/configuration"
6
+ require "minato_logger/formatters"
7
+ require "minato_logger/logger"
8
+ require "minato_logger/rails" if defined? Rails::Railtie
9
+
10
+ module MinatoLogger
11
+ class << self
12
+ def configure
13
+ if block_given?
14
+ yield(Configuration.default)
15
+ else
16
+ Configuration.default
17
+ end
18
+ end
19
+
20
+ def config
21
+ @config ||= Configuration.default
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minato_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13.pre.2
4
+ version: 0.1.13.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferreri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,10 +70,12 @@ files:
70
70
  - Rakefile
71
71
  - compose.yml
72
72
  - lib/minato_logger.rb
73
+ - lib/minato_logger/configuration.rb
73
74
  - lib/minato_logger/formatters.rb
74
75
  - lib/minato_logger/formatters/base_formatter.rb
75
76
  - lib/minato_logger/formatters/fluent_bit.rb
76
77
  - lib/minato_logger/logger.rb
78
+ - lib/minato_logger/middleware.rb
77
79
  - lib/minato_logger/rails.rb
78
80
  - lib/minato_logger/version.rb
79
81
  - minato_logger.gemspec