tee_logger 3.2.1 → 3.2.2

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
  SHA1:
3
- metadata.gz: 9698a06d0147a9728b46a704c455ac4bbb72b0ee
4
- data.tar.gz: 909f2f8b60a04dc98fa19bad8085650f9bd2a0ea
3
+ metadata.gz: d28e952333c675499313816763f1faf5c908afde
4
+ data.tar.gz: 71321a829dffd0b7b6126722c449556232d1764d
5
5
  SHA512:
6
- metadata.gz: e9df0fcc964c6f734a52936aacb66650575de2475e4a54805199c6772a41037ad0c4617c3455e85b3a35697f3adac7e7baa6c51e9f2f8b0a8ef9461f3189464c
7
- data.tar.gz: 1e330f7fa8e445ee507c9604d1dd2b8d7c07dd3294537aed936abdf44c0e495b566bd2df5ada856acf61902ced1768035cb1f8b3b43830db2ad9be35ea1f0c48
6
+ metadata.gz: 16300440ff7dffdd75291528eb42ea1403ad72673e72fd87a5a35bd3ee5f2e422ab38cb88b96d6105ff8b009794e20d31386237d34d75c7f5cd8f8716edb126d
7
+ data.tar.gz: 08973e7cdf09bb898f9b984dd5786c24d4132c26defc05c28e6271d1b22f5727828de7ef73995152baf0ec03cecc1665728f8cba84106b4f0575d9ba900dbdc6
@@ -0,0 +1,2 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
@@ -1,3 +1,11 @@
1
+ # v3.2.2
2
+ - [issue #17](https://github.com/k-ta-yamada/tee_logger/issues/17)
3
+ default settings for extend and include
4
+
5
+ # v3.2.1
6
+ - [issue #18](https://github.com/k-ta-yamada/tee_logger/issues/18)
7
+ use initial value `DEFAULT_FILE`, it's change TeeLogger.logdev
8
+
1
9
  # v3.2.0
2
10
  - [issue #15](https://github.com/k-ta-yamada/tee_logger/issues/15)
3
11
  Before extend or include the module, allow the setting of logdev
data/README.md CHANGED
@@ -169,15 +169,18 @@ module YourAwesomeModule
169
169
  end
170
170
  ```
171
171
 
172
- ### logfile name setting
172
+ ### configuration logfile name, progname, level, formatter, and datetime_format.
173
173
  ```ruby
174
174
  require 'tee_logger'
175
175
 
176
- # Before extend or include the module, allow the setting of logdev
177
- # sorry, `TeeLogger.logev` is deprecate.
176
+ # Before extend or include the module, allow the configuration.
178
177
  # TeeLogger.logdev = 'log1.log'
179
178
  TeeLogger.configure do |config|
180
179
  config.logdev = 'log1.log'
180
+ config.level = Logger::Severity::INFO
181
+ config.progname = 'AwesomeApp'
182
+ config.formatter = proc { |s, t, p, m| "#{s} #{t} #{p} #{m}\n" }
183
+ # config.datetime_format = '%Y%m%d %H%M%S '
181
184
  end
182
185
 
183
186
  class YourAwesomeClass
@@ -188,8 +191,10 @@ class YourAwesomeClass
188
191
  end
189
192
  end
190
193
 
191
- # Before extend or include the module, allow the setting of logdev
192
- # sorry, `TeeLogger.logev` is deprecate.
194
+ # reset configuration
195
+ TeeLogger.configuration_reset
196
+
197
+ # NOTE: sorry, `TeeLogger.logev` is deprecate.
193
198
  TeeLogger.logdev = 'log2.log'
194
199
  module YourAwesomeModule
195
200
  extend TeeLogger
@@ -25,7 +25,7 @@ module TeeLogger
25
25
  mod.define_singleton_method(:logger) do
26
26
  return @logger if @logger
27
27
  @logger = TeeLogger.new
28
- @logger.progname = mod
28
+ @logger.progname = TeeLogger.progname || mod
29
29
  @logger
30
30
  end
31
31
  end
@@ -37,7 +37,7 @@ module TeeLogger
37
37
  define_method(:logger) do
38
38
  return @logger if @logger
39
39
  @logger = TeeLogger.new
40
- @logger.progname = klass.name
40
+ @logger.progname = TeeLogger.progname || klass.name
41
41
  @logger
42
42
  end
43
43
  end
@@ -2,7 +2,18 @@
2
2
  module TeeLogger
3
3
  # configuration
4
4
  module Configration
5
- Configration = Struct.new(:logdev)
5
+ extend Gem::Deprecate
6
+
7
+ # @attr logdev [String, File]
8
+ # @attr level [Logger::Severity, Integer]
9
+ # @attr progname [String, Symbol]
10
+ # @attr formatter [Logger::Formatter, Proc]
11
+ # @attr datetime_format [String]
12
+ Configration = Struct.new(:logdev,
13
+ :level,
14
+ :progname,
15
+ :formatter,
16
+ :datetime_format)
6
17
 
7
18
  # Yields the global configuration to a block.
8
19
  # @yield [Configuration] global configuration
@@ -22,8 +33,6 @@ module TeeLogger
22
33
  def logdev=(logdev)
23
34
  configuration.logdev = logdev
24
35
  end
25
-
26
- extend Gem::Deprecate
27
36
  deprecate :logdev=, 'TeeLogger.configure', 2016, 1
28
37
 
29
38
  # @return [String, File] `configuration.logdev` or `DEFAULT_FILE`.
@@ -31,6 +40,26 @@ module TeeLogger
31
40
  configuration.logdev || DEFAULT_FILE
32
41
  end
33
42
 
43
+ # @return `configuration.level`
44
+ def level
45
+ configuration.level
46
+ end
47
+
48
+ # @return `configuration.progname`
49
+ def progname
50
+ configuration.progname
51
+ end
52
+
53
+ # @return `configuration.formatter`
54
+ def formatter
55
+ configuration.formatter
56
+ end
57
+
58
+ # @return `configuration.datetime_format`
59
+ def datetime_format
60
+ configuration.datetime_format
61
+ end
62
+
34
63
  private
35
64
 
36
65
  def configuration
@@ -1,23 +1,27 @@
1
1
  # namespace
2
2
  module TeeLogger
3
3
  # no param of filename, set this filename
4
- DEFAULT_FILE = './tee_logger.log'
4
+ DEFAULT_FILE = './tee_logger.log'.freeze
5
5
 
6
- # Implements targets
7
- LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal]
6
+ # configured attributes
7
+ CONFIGURED_ATTRIBUTES =
8
+ [:level, :progname, :formatter, :datetime_format].freeze
9
+
10
+ # implements targets
11
+ LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
8
12
 
9
13
  # defined logdev names
10
- LOGDEV_NAMES = [:console, :logfile]
14
+ LOGDEV_NAMES = [:console, :logfile].freeze
11
15
 
12
16
  # defined paired of logdev name
13
- LOGDEV_REVERSE = { console: :logfile, logfile: :console }
17
+ LOGDEV_REVERSE = { console: :logfile, logfile: :console }.freeze
14
18
 
15
19
  # empty format
16
20
  FORMATTER_FOR_DISABLING = proc { |_severity, _time, _progname, _msg| '' }
17
21
 
18
22
  # using TeeLogger::Utils.extract_options
19
- # @param logdev_name [Symbol]
20
- # @param indent_level [Fixnum]
23
+ # @attr logdev_name [Symbol]
24
+ # @attr indent_level [Fixnum]
21
25
  ParsedOption = Struct.new(:logdev_name, :indent_level)
22
26
 
23
27
  # LOGDEV_NAMES not included error
@@ -37,7 +37,8 @@ module TeeLogger
37
37
  end
38
38
 
39
39
  include Utils
40
- attr_reader :level, :progname, :formatter, :datetime_format
40
+ # attr_reader :level, :progname, :formatter, :datetime_format
41
+ attr_reader(*CONFIGURED_ATTRIBUTES)
41
42
 
42
43
  # @param logdev [String]
43
44
  # @param shift_age [Integer]
@@ -48,6 +49,7 @@ module TeeLogger
48
49
  @logfile = Logger.new(logdev || TeeLogger.logdev, shift_age, shift_size)
49
50
 
50
51
  @level, @progname, @formatter, @datetime_format = nil
52
+ configuration
51
53
  end
52
54
 
53
55
  define_logging_methods :debug
@@ -66,8 +68,8 @@ module TeeLogger
66
68
  def level=(level)
67
69
  @console.level = @logfile.level = @level = level
68
70
  end
69
- alias_method :sev_threshold, :level
70
- alias_method :sev_threshold=, :level=
71
+ alias sev_threshold level
72
+ alias sev_threshold= level=
71
73
 
72
74
  # @param name [String, Symbol]
73
75
  def progname=(name = nil)
@@ -79,11 +81,11 @@ module TeeLogger
79
81
  @console.formatter = @logfile.formatter = @formatter = formatter
80
82
  end
81
83
 
82
- # @param formatter
83
- def datetime_format=(format)
84
+ # @param datetime_format
85
+ def datetime_format=(datetime_format)
84
86
  @console.datetime_format =
85
87
  @logfile.datetime_format =
86
- @datetime_format = format
88
+ @datetime_format = datetime_format
87
89
  end
88
90
 
89
91
  # @param logdev_name [String, Symbol]
@@ -107,6 +109,13 @@ module TeeLogger
107
109
 
108
110
  private
109
111
 
112
+ def configuration
113
+ CONFIGURED_ATTRIBUTES.each do |method_name|
114
+ value = TeeLogger.send(method_name)
115
+ send("#{method_name}=", value) unless value.nil?
116
+ end
117
+ end
118
+
110
119
  def logging(name, progname, logdev_name = nil, &block)
111
120
  if logdev_name
112
121
  disable(logdev_name) { logging(name, progname, &block) }
@@ -1,5 +1,5 @@
1
1
  # namespace
2
2
  module TeeLogger
3
3
  # version number
4
- VERSION = '3.2.1'
4
+ VERSION = '3.2.2'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tee_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-ta-yamada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler