minato_logger 0.1.13.pre.3 → 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: 1c9c3f95a5063eec9edc3da85724cbb7fb9193cea2ed72d53c5d9eeecdfaaef2
4
- data.tar.gz: 45af5306aab0c00c9718ddf01fe3b697435cba213e2a4afd5eecf53395976b55
3
+ metadata.gz: 8912274da7dd77fae6f70e2236079b5ed24df2aef0326ef1cd0467aed0cd2dcc
4
+ data.tar.gz: 9fe88a71c8273fa4945b74d3d640761b6fc8bfb2c2bca0ae63e25cfb3b82fc2d
5
5
  SHA512:
6
- metadata.gz: b51adbfc534b440e3c9e1a6c2e46b688c95fb3d8121bfc73c693551c04652018aa5e9b3e68a767fa2150bedd1bfc6975d62eac51815f2aea4af9480bd5db723b
7
- data.tar.gz: 83655a46dbe89b6cb9260e9f892d9c29ba9d3b2e05cc02abe34de72d401def53ff6ff1832fbc44b5b7e293ce1cedf83763a96400aa58a3ed561f0285d3b8e4d8
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
@@ -11,17 +11,19 @@ module MinatoLogger
11
11
 
12
12
  def call(severity, timestamp, _progname, message)
13
13
  log = add_message_to_logs({ severity: severity, time: timestamp }, message)
14
- log = add_trace_to_logs(log)
14
+ log = apply_middlewares(log)
15
15
 
16
16
  "#{log.to_json}\n"
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def add_trace_to_logs(log)
22
- return log if MinatoLogger.config.trace_logs.nil?
21
+ def apply_middlewares(log)
22
+ MinatoLogger.config.middleware.middlewares.each do |middleware|
23
+ log = middleware.new.call(log)
24
+ end
23
25
 
24
- MinatoLogger.config.trace_logs.send(:call, log)
26
+ log
25
27
  end
26
28
 
27
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,14 +2,10 @@
2
2
 
3
3
  module MinatoLogger
4
4
  class Railtie < ::Rails::Railtie
5
- config.minato_logger = ActiveSupport::OrderedOptions.new
5
+ config.minato_logger = MinatoLogger::Configuration.default
6
6
 
7
7
  config.after_initialize do |app|
8
- app.config.colorize_logging = false
9
-
10
- MinatoLogger.configure do |config|
11
- config.trace_logs = app.config.minato_logger.trace_logs
12
- end
8
+ app.config.colorize_logging = false if Rails.env.production?
13
9
  end
14
10
  end
15
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinatoLogger
4
- VERSION = "0.1.13-3"
4
+ VERSION = "0.1.13-4"
5
5
  end
data/lib/minato_logger.rb CHANGED
@@ -1,20 +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::Railtie
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
7
9
 
8
10
  module MinatoLogger
9
- class Config
10
- attr_accessor :trace_logs
11
- end
12
-
13
- def self.config
14
- @config ||= Config.new
15
- end
11
+ class << self
12
+ def configure
13
+ if block_given?
14
+ yield(Configuration.default)
15
+ else
16
+ Configuration.default
17
+ end
18
+ end
16
19
 
17
- def self.configure
18
- yield config if block_given?
20
+ def config
21
+ @config ||= Configuration.default
22
+ end
19
23
  end
20
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.3
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-14 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