tee_logger 2.2.0 → 2.3.0

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: 71e96ed7955c6a5d8f3ecbe2718ae133c86dcf57
4
- data.tar.gz: 2a488ff3ab2b22a5515726a6b1c3b0be109bdb4b
3
+ metadata.gz: 59a9bb33bea8cf8a4daacb87ef8373c7fc600060
4
+ data.tar.gz: 2caed1cc30207142e63c1793069bbcdf53a048e4
5
5
  SHA512:
6
- metadata.gz: 54585f50bcb1fc7668548848b7278fa70c1c5207140686f55ebf982fc59b7c6e82648b7521a3afbfe8c26963f07973cf698f1e97d0a7dae95a0b3c5a4362870c
7
- data.tar.gz: 1e3bafb69459f0df8d2da4f7e2c6f6f570dcb09b73ebd7baae193002dbff6c5fee7a66433d145f0c1f76a4f170672d6ff7e6d3ccc8badaca8391ed28d43ca287
6
+ metadata.gz: fd999b91c1cd80c98115225a51a23785833f5697e6d4b747da45228c898e09f58e92f711bcc0718bb901f25a939d8774e4bb538a55e359923c562d9fa6bd0640
7
+ data.tar.gz: a6fe565e2e2055101e306d938716c63099945ff82d1ed8da9e13bc53450dceea5960d305e1fae76331f72e4e9a100b2df35aa9b2de75ce480bd67cb7749a1231
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
2
- --color
1
+ --color
2
+ --format documentation
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.3.0
2
+ - remove TeeLogger.attr_reader
3
+ - and rename instance variable: @logger => @logfile
4
+ - implementation `#level` and `level=`
5
+ - implementation `#formatter` and `formatter=`
6
+
1
7
  # 2.2.0
2
8
  - disabling and enabling
3
9
 
data/README.md CHANGED
@@ -1,18 +1,24 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/tee_logger.svg)](http://badge.fury.io/rb/tee_logger)
2
2
  [![Build Status](https://travis-ci.org/k-ta-yamada/tee_logger.svg)](https://travis-ci.org/k-ta-yamada/tee_logger)
3
3
 
4
- Sorry, I changed Usage.
4
+ > Sorry, I changed Usage from version 2.0.0
5
5
 
6
6
  - [Rubygems.org](https://rubygems.org/gems/tee_logger)
7
7
  - [GitHub](https://github.com/k-ta-yamada/tee_logger)
8
+ - [RubyDoc.info](http://www.rubydoc.info/gems/tee_logger/2.2.0)
8
9
 
9
10
  # TeeLogger
10
11
 
11
- logging to logfile and standard output.
12
+ logging to file and standard output.
13
+ require standard library only.
14
+
15
+
16
+ ## Characteristic
12
17
 
13
- Characteristic
14
18
  - simple: use standard lib only.
15
19
  - like Logger: see usage.
20
+ - enabled or disabled by switching the output of the console and the logfile.
21
+
16
22
 
17
23
  ## Installation
18
24
 
@@ -30,43 +36,64 @@ Or install it yourself as:
30
36
 
31
37
  $ gem install tee_logger
32
38
 
39
+
33
40
  ## Usage
34
41
 
35
42
  ```ruby
36
43
  require 'tee_logger'
37
44
 
38
- # Logger.new like options
39
- tl = TeeLogger.new('./tee_logger.log', 5, 1_024)
45
+ # Logger.new like options(logdev, shift_age, shift_size)
46
+ # options default value is
47
+ # logdev = './tee_logger.log'
48
+ # shift_age = 0
49
+ # shift_size = 1_048_576
50
+ tl = TeeLogger.new
40
51
 
41
- tl.debug(:progname) { 'hello world' }
52
+ # let's logging
53
+ tl.debug 'hello' # => D, [2015-09-10T00:36:45.925312 #16227] DEBUG -- : hello
54
+ tl.debug(:progname) { 'hello world' } # => D, [2015-09-10T00:37:31.940226 #16227] DEBUG -- progname: hello world
42
55
  tl.progname = 'App'
43
- tl.debug('hello tee_logger')
56
+ tl.debug 'hello tee_logger' # => D, [2015-09-10T00:38:38.704274 #16227] DEBUG -- App: hello tee_logger
44
57
 
45
- # console only
46
- tl.console.info('console only')
47
-
48
- # logfile only
49
- tl.logger.info('logger only')
50
-
51
- # disable and enable console output
58
+ # disable console output
52
59
  tl.disable(:console)
53
60
  tl.info 'this message is logfile only'
61
+
62
+ # enable console output
54
63
  tl.enable(:console)
55
64
  tl.info 'this message is logfile and console'
56
65
 
57
- # disable and enable logfile output
58
- tl.disable(:logger)
66
+ # disable logfile output
67
+ tl.disable(:logfile)
59
68
  tl.info 'this message is consle only'
60
- tl.enable(:logger)
69
+
70
+ # enable logfile output
71
+ tl.enable(:logfile)
61
72
  tl.info 'this message is logfile and console'
73
+
74
+ # and others like Logger's
75
+ tl.debug? # => true
76
+ tl.info? # => true
77
+ tl.warn? # => true
78
+ tl.error? # => true
79
+ tl.fatal? # => true
80
+
81
+ tl.level # => 0
82
+ tl.level = Logger::INFO
83
+ tl.debug 'this message is not logging'
84
+
85
+ tl.formatter # => nil or Proc
86
+ tl.formatter = proc {|severity, datetime, progname, message| "#{severity}:#{message}" }
62
87
  ```
63
88
 
89
+
64
90
  ## Development
65
91
 
66
92
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
93
 
68
94
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
95
 
96
+
70
97
  ## Contributing
71
98
 
72
99
  Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/tee_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
@@ -2,6 +2,9 @@ require 'logger'
2
2
 
3
3
  # namespace
4
4
  module TeeLogger
5
+ # no param of filename, set this filename
5
6
  DEFAULT_FILE = './tee_logger.log'
6
- LOGGING_METHODS = %i(debug info warn error fatal).freeze
7
+
8
+ # Implements targets
9
+ LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
7
10
  end
@@ -1,4 +1,5 @@
1
1
  # namespace
2
2
  module TeeLogger
3
- VERSION = '2.2.0'
3
+ # version number
4
+ VERSION = '2.3.0'
4
5
  end
data/lib/tee_logger.rb CHANGED
@@ -1,77 +1,115 @@
1
1
  require 'tee_logger/version'
2
2
  require 'tee_logger/constants'
3
-
4
3
  require 'logger'
5
4
 
6
5
  # namespace
7
6
  module TeeLogger
8
7
  # shortcut for TeeLogger::TeeLogger.new
8
+ # @see TeeLogger
9
9
  def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
10
10
  TeeLogger.new(logdev, shift_age, shift_size)
11
11
  end
12
12
 
13
13
  # main
14
+ # @see http://www.rubydoc.info/stdlib/logger/Logger Logger
14
15
  class TeeLogger
15
- attr_reader :logger, :console
16
-
16
+ # @param logdev String
17
+ # @param shift_age Integer
18
+ # @param shift_size Integer
19
+ # @see Logger#initialize
17
20
  def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
18
- @logger = Logger.new(logdev, shift_age, shift_size)
21
+ @logfile = Logger.new(logdev, shift_age, shift_size)
19
22
  @console = Logger.new($stdout)
20
23
  end
21
24
 
22
- # logging methods.
23
- LOGGING_METHODS.each do |name|
24
- define_method(name) do |progname = nil, &block|
25
- @logger.send(name, progname, &block)
26
- @console.send(name, progname, &block)
25
+ class << self
26
+ private
27
+
28
+ # @!macro [attach] loglevel_check_methods
29
+ # @!method $1(name)
30
+ # @return [Boolean]
31
+ def define_loglevel_check_methods(name)
32
+ define_method(name) do
33
+ @logfile.send(name)
34
+ @console.send(name)
35
+ end
27
36
  end
28
- end
29
37
 
30
- # check logging level methods.
31
- LOGGING_METHODS.map { |v| "#{v}?" }.each do |name|
32
- define_method(name) do
33
- # TODO: which?
34
- # @logger.send(name)
35
- @console.send(name)
38
+ # @!macro [attach] logging_methods
39
+ # @!method $1(progname = nil, &block)
40
+ # logging $1 level message.
41
+ # @return true
42
+ def define_logging_methods(name)
43
+ define_method(name) do |progname = nil, &block|
44
+ @logfile.send(name, progname, &block)
45
+ @console.send(name, progname, &block)
46
+ end
36
47
  end
37
48
  end
38
49
 
39
- # TODO: Too miscellaneous
40
- def disable(target)
41
- instance_variable_get("@#{target}").formatter = proc { |s, dt, p, m| }
50
+ define_loglevel_check_methods :debug?
51
+ define_loglevel_check_methods :info?
52
+ define_loglevel_check_methods :warn?
53
+ define_loglevel_check_methods :error?
54
+ define_loglevel_check_methods :fatal?
55
+
56
+ define_logging_methods :debug
57
+ define_logging_methods :info
58
+ define_logging_methods :warn
59
+ define_logging_methods :error
60
+ define_logging_methods :fatal
61
+
62
+ # TODO: which value?
63
+ # @return [Integer]
64
+ def level
65
+ @logfile.level
66
+ @console.level
42
67
  end
43
68
 
44
- # TODO: Too miscellaneous
45
- def enable(target)
46
- instance_variable_get("@#{target}").formatter = Logger::Formatter.new
69
+ # @param level [Integer]
70
+ def level=(level)
71
+ @logfile.level = level
72
+ @console.level = level
47
73
  end
74
+ alias_method :sev_threshold, :level
75
+ alias_method :sev_threshold=, :level=
48
76
 
77
+ # TODO: both values?
78
+ # @return [String]
49
79
  def progname
50
- # TODO: which?
51
- # @logger.progname
80
+ @logfile.progname
52
81
  @console.progname
53
82
  end
54
83
 
84
+ # @param name [String, Symbol]
55
85
  def progname=(name = nil)
56
- # TODO: which?
57
- # @logger.progname = name
86
+ @logfile.progname = name
58
87
  @console.progname = name
59
88
  end
60
89
 
90
+ # TODO: both values?
91
+ # @return [String]
61
92
  def formatter
62
- # TODO: which?
63
- # @logger.formatter
93
+ @logfile.formatter
64
94
  @console.formatter
65
95
  end
66
96
 
97
+ # @param formatter
67
98
  def formatter=(formatter)
68
- @logger.formatter = formatter
99
+ @logfile.formatter = formatter
69
100
  @console.formatter = formatter
70
101
  end
71
102
 
72
- # def close
73
- # @logger.close
74
- # # @console.close
75
- # end
103
+ # @todo Too miscellaneous
104
+ # @param target [String, Symbol]
105
+ def disable(target)
106
+ instance_variable_get("@#{target}").formatter = proc { |_, _, _, _| }
107
+ end
108
+
109
+ # @todo Too miscellaneous
110
+ # @param target [String, Symbol]
111
+ def enable(target)
112
+ instance_variable_get("@#{target}").formatter = Logger::Formatter.new
113
+ end
76
114
  end
77
115
  end
data/tee_logger.gemspec CHANGED
@@ -1,33 +1,36 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tee_logger/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'tee_logger'
8
- spec.version = TeeLogger::VERSION
9
- spec.authors = ['k-ta-yamada']
10
- spec.email = ['key.luvless@gmail.com']
11
-
12
- spec.summary = 'logging to file and standard output'
13
- spec.description = 'logging to file and standard output'
14
- spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_development_dependency 'bundler', '~> 1.10'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec'
25
-
26
- spec.add_development_dependency 'pry'
27
- spec.add_development_dependency 'pry-doc'
28
- spec.add_development_dependency 'pry-theme'
29
- spec.add_development_dependency 'rubocop'
30
-
31
- spec.add_development_dependency 'capture_stdout'
32
- spec.add_development_dependency 'fakefs'
33
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tee_logger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tee_logger'
8
+ spec.version = TeeLogger::VERSION
9
+ spec.authors = ['k-ta-yamada']
10
+ spec.email = ['key.luvless@gmail.com']
11
+
12
+ spec.summary = 'logging to file and standard output.'
13
+ spec.description =
14
+ 'logging to file and standard output. require standard library only.'
15
+
16
+ spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'fuubar'
28
+
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'pry-doc'
31
+ spec.add_development_dependency 'pry-theme'
32
+ spec.add_development_dependency 'rubocop'
33
+
34
+ spec.add_development_dependency 'capture_stdout'
35
+ spec.add_development_dependency 'fakefs'
36
+ 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: 2.2.0
4
+ version: 2.3.0
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: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +150,7 @@ dependencies:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
- description: logging to file and standard output
153
+ description: logging to file and standard output. require standard library only.
140
154
  email:
141
155
  - key.luvless@gmail.com
142
156
  executables: []
@@ -181,6 +195,6 @@ rubyforge_project:
181
195
  rubygems_version: 2.4.8
182
196
  signing_key:
183
197
  specification_version: 4
184
- summary: logging to file and standard output
198
+ summary: logging to file and standard output.
185
199
  test_files: []
186
200
  has_rdoc: