smart_logger_wrapper 0.1.1 → 0.2.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
  SHA1:
3
- metadata.gz: 444b6317f04b10930e9ad6ec0d0efde371ecc9ca
4
- data.tar.gz: 39aa6ff2667da7d5f8ec1b83d8bfb3bdd09e3307
3
+ metadata.gz: 1c8ddd160c2ce65d59bc832aca8b0aa4c16294be
4
+ data.tar.gz: 1943139dbae45139e9bcc690cf095f45ed252625
5
5
  SHA512:
6
- metadata.gz: 07f7e3686b7e480b09b20cd39f1a09b62af4b004073792a2f46076ad841b65ede344f3cc28db455fd9fed4ac6a42c7d4abd318295f2e1e2be28ac9606daa5d4f
7
- data.tar.gz: 5da56581d007acb6d0646e817fbf2d85a78b52b72f0352810172a59cb330eba5fb059d0786970598c59fa81418e7c8b6047026d357c730b85048f7de9ac8c7a9
6
+ metadata.gz: ea9d1354d530b8a45e82b0421225a13a3ba7a794026c3072b914e7f094913285e29160e68a94521c742e05c6598db461b962a45a9d377a6b95c891de53aa089d
7
+ data.tar.gz: 29256c2b98a5826d298abb908dba83c37d017dcc854ee3c934c3e1b18e106e8f8128ec98c5b1a47f459462cb92c21d06611fd6fe10182fbeaddd7d7c065daf52
data/README.md CHANGED
@@ -31,12 +31,13 @@ Wrap your logger with `SmartLoggerWrapper`, for example, in `config/environments
31
31
 
32
32
  Note that it is strongly recommended to use the wrapper for all environments so that you can avoid exceptions such as `NoMethodError` due to the unique features of this library.
33
33
 
34
- You may want to put log messages to STDOUT in the development environment. Then:
34
+ You may want to put log messages to `STDOUT` in your development environment. Then:
35
35
 
36
- ```
37
- logger = ActiveSupport::Logger.new("log/development.log")
38
- logger.extend ActiveSupport::Logger.broadcast(ActiveSupport::Logger.new(STDOUT))
39
- config.logger = SmartLoggerWrapper.new(logger)
36
+ ```ruby
37
+ config.logger = SmartLoggerWrapper.new(
38
+ SmartLoggerWrapper.new(Logger.new("log/development.log")).with_position,
39
+ ActiveSupport::Logger.new(STDOUT)
40
+ )
40
41
  ```
41
42
 
42
43
  ## Usage
@@ -52,9 +53,12 @@ require 'smart_logger_wrapper'
52
53
  logger = SmartLoggerWrapper.new(Logger.new('log/development.log'))
53
54
 
54
55
  logger.info 'Call logging methods as usual.'
56
+
57
+ # You can wrap multiple loggers
58
+ logger2 = SmartLoggerWrapper.new(Logger.new('log/development.log'), Logger.new(STDOUT))
55
59
  ```
56
60
 
57
- The compatibles must respond to `#log` with the same arguments as `Logger#log`.
61
+ The compatibles must respond to `#add` with the same arguments as `Logger#add`.
58
62
 
59
63
  ### Feature 1: Integrate multiple logger calls
60
64
 
@@ -1,3 +1,3 @@
1
1
  class SmartLoggerWrapper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -14,10 +14,10 @@ class SmartLoggerWrapper
14
14
  unknown: UNKNOWN
15
15
  }.freeze
16
16
 
17
- attr_reader :logger, :options
17
+ attr_reader :loggers, :options
18
18
 
19
- def initialize(logger = Logger.new(STDOUT), **options)
20
- @logger = logger
19
+ def initialize(logger = Logger.new(STDOUT), *loggers, **options)
20
+ @loggers = [logger, *loggers]
21
21
  @options = options
22
22
  end
23
23
 
@@ -42,14 +42,18 @@ class SmartLoggerWrapper
42
42
  Options.apply_all!(messages, options)
43
43
  true
44
44
  rescue Options::ApplicationError => e
45
- logger.error(<<~EOM)
46
- Failed to apply options: #{e.inspect}
47
- #{e.backtrace.join("\n")}
48
- EOM
45
+ loggers.each do |logger|
46
+ logger.error(<<~EOM)
47
+ Failed to apply options: #{e.inspect}
48
+ #{e.backtrace.join("\n")}
49
+ EOM
50
+ end
49
51
  false
50
52
  end.tap do |succeeded|
51
53
  messages.each do |message|
52
- logger.add(severity, nil, message)
54
+ loggers.each do |logger|
55
+ logger.add(severity, nil, message)
56
+ end
53
57
  end
54
58
  end
55
59
  end
@@ -70,12 +74,14 @@ class SmartLoggerWrapper
70
74
  def method_missing(method_name, *args, &block)
71
75
  if Options.defined_option?(method_name)
72
76
  # if there is an defined option with the same name as the method name, return a new logger with the option.
73
- new_logger = self.class.new(logger, **options.merge(method_name => args.first))
77
+ new_logger = self.class.new(*loggers, **options.merge(method_name => args.first))
74
78
  return block.(new_logger) if block_given?
75
79
  new_logger
76
80
  else
77
81
  # otherwise, call the method of the warpped logger.
78
- logger.public_send(method_name, *args, &block)
82
+ loggers.each do |logger|
83
+ logger.public_send(method_name, *args, &block)
84
+ end
79
85
  end
80
86
  end
81
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_logger_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Katsura