minato_logger 0.1.13.pre.3 → 0.1.13.pre.5

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: 7673fcdba540e6485a39fccf31e2bd4ede8239b07ba7d0555c972f8dcb56f77e
4
+ data.tar.gz: a338ab6a4d99d3ba5efdbf706d2c68f2641adaca413d0517cfab57864c84578e
5
5
  SHA512:
6
- metadata.gz: b51adbfc534b440e3c9e1a6c2e46b688c95fb3d8121bfc73c693551c04652018aa5e9b3e68a767fa2150bedd1bfc6975d62eac51815f2aea4af9480bd5db723b
7
- data.tar.gz: 83655a46dbe89b6cb9260e9f892d9c29ba9d3b2e05cc02abe34de72d401def53ff6ff1832fbc44b5b7e293ce1cedf83763a96400aa58a3ed561f0285d3b8e4d8
6
+ metadata.gz: 45f4a901a5be41467bc4a94138a743fbd2775dcc518ef1bdfc72b171b8ee9d6b7663e11f5b3615247e016361487d54f4555df7077c413d372953ae84ed666ea1
7
+ data.tar.gz: 6d4537ff78aaeba4aab55a963a5ddf5860dfe9870a60c935c244513a70ec2b3c006ec52342aef4d762840b60d5c74a582ba3a42448745588c580365ec034a1be
@@ -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
@@ -5,6 +5,7 @@ require "active_support"
5
5
  module MinatoLogger
6
6
  module Formatters
7
7
  class BaseFormatter < Logger::Formatter
8
+ include ActiveSupport::TaggedLogging::Formatter
8
9
  end
9
10
  end
10
11
  end
@@ -1,27 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/tagged_logging"
4
- require "google/cloud/trace"
5
3
  require "json"
6
4
 
7
5
  module MinatoLogger
8
6
  module Formatters
9
7
  class FluentBit < BaseFormatter
10
- include ActiveSupport::TaggedLogging::Formatter
11
-
12
8
  def call(severity, timestamp, _progname, message)
13
- log = add_message_to_logs({ severity: severity, time: timestamp }, message)
14
- log = add_trace_to_logs(log)
9
+ tagged_message = add_tags_to_message(message)
10
+ log = add_message_to_logs({ severity: severity, time: timestamp }, tagged_message)
11
+ log = apply_middlewares(log)
15
12
 
16
13
  "#{log.to_json}\n"
17
14
  end
18
15
 
19
16
  private
20
17
 
21
- def add_trace_to_logs(log)
22
- return log if MinatoLogger.config.trace_logs.nil?
18
+ def apply_middlewares(log)
19
+ MinatoLogger.config.middleware.middlewares.each do |middleware|
20
+ log = middleware.new.call(log)
21
+ end
23
22
 
24
- MinatoLogger.config.trace_logs.send(:call, log)
23
+ log
25
24
  end
26
25
 
27
26
  def add_message_to_logs(log, message)
@@ -29,6 +28,18 @@ module MinatoLogger
29
28
 
30
29
  log.merge({ message: message, ruby_version: RUBY_VERSION })
31
30
  end
31
+
32
+ def add_tags_to_message(msg)
33
+ return msg unless tags_text.present?
34
+
35
+ if msg.is_a?(Hash)
36
+ msg["message"] = "#{tags_text} #{msg["message"]}"
37
+ else
38
+ msg = "#{tags_text} #{msg}"
39
+ end
40
+
41
+ msg
42
+ end
32
43
  end
33
44
  end
34
45
  end
@@ -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-5"
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.5
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-03-01 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