tee_logger 1.1.0 → 2.0.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: 68e6895e0af9a49ee888c733815c09316e5dd412
4
- data.tar.gz: 9c7b5ce69e3c445393f38acd60de08fca85f7549
3
+ metadata.gz: be09165c03c07b79e29ef887ca1d88c9ef85afee
4
+ data.tar.gz: 8d12405174d93f5d051c8a58a72daec3c46abf34
5
5
  SHA512:
6
- metadata.gz: b23d0cb8cfa8caa9e426038b83b4d06097822a3a80715fc14c5662bfc7920cc35f80e567802649473f531ea8b2dc4d99ecd03a937d5bf257b942ccb5e7132f11
7
- data.tar.gz: 0a96a4049b5d6232b062c1830c222b845f364caf405c6319c18caaa98a6f81dd50bffc5d76fc877ff49dcbe221db7f1a57b26611bc4999ecbce0ac408ca99700
6
+ metadata.gz: 4dda6fea4467d09cab1402eba705fe2cbb6666074f1a7f1e0f00858c936995f08fd8b802703ba1014fba9e3dc6bfbe3b8631bd4c51255013eab4858eeb0e197c
7
+ data.tar.gz: 79b20992b4be5ae2f986b414601040e29e888f38955ebfa5daa6d683fb1f072c2064232a4b3d432e18109346c5d1ccddafa89f9e7e349cc1cd2bc6b0f3a0c60b
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
+
2
+ Sorry, I changed Usage.
3
+
4
+ - [rubygems](https://rubygems.org/gems/tee_logger)
5
+ - [github](https://github.com/k-ta-yamada/tee_logger)
6
+
1
7
  # TeeLogger
2
8
 
3
- logging to logfile and standard output
9
+ logging to logfile and standard output.
10
+
11
+ Characteristic
12
+ - simple: use standard lib only.
13
+ - like Logger: see usage.
4
14
 
5
15
  ## Installation
6
16
 
@@ -22,68 +32,35 @@ Or install it yourself as:
22
32
 
23
33
  ```ruby
24
34
  require 'tee_logger'
25
- TeeLogger.setup
26
-
27
- TeeLogger.debug 'hello' # => output console and logfile
28
- TeeLogger.info 'hello' # => output console and logfile
29
- TeeLogger.warn 'hello' # => output console and logfile
30
- TeeLogger.error 'hello' # => output console and logfile
31
- TeeLogger.fatal 'hello' # => output console and logfile
32
-
33
- TeeLogger.console_debug 'hello' # => output console only
34
- TeeLogger.console_info 'hello' # => output console only
35
- TeeLogger.console_warn 'hello' # => output console only
36
- TeeLogger.console_error 'hello' # => output console only
37
- TeeLogger.console_fatal 'hello' # => output console only
38
-
39
- TeeLogger.logger_debug 'hello' # => output logfile only
40
- TeeLogger.logger_info 'hello' # => output logfile only
41
- TeeLogger.logger_warn 'hello' # => output logfile only
42
- TeeLogger.logger_error 'hello' # => output logfile only
43
- TeeLogger.logger_fatal 'hello' # => output logfile only
44
- ```
45
35
 
46
- and more
47
- - debug? # => Boolean
48
- - info? # => Boolean
49
- - warn? # => Boolean
50
- - error? # => Boolean
51
- - fatal? # => Boolean
52
- - console_debug? # => Boolean
53
- - console_info? # => Boolean
54
- - console_warn? # => Boolean
55
- - console_error? # => Boolean
56
- - console_fatal? # => Boolean
57
- - logger_debug? # => Boolean
58
- - logger_info? # => Boolean
59
- - logger_warn? # => Boolean
60
- - logger_error? # => Boolean
61
- - logger_fatal? # => Boolean
62
-
63
- ## define logfile name
64
-
65
- default logfile is `./tee_logger.log`.
66
-
67
- you can change logfile.
36
+ # Logger.new like options
37
+ tl = TeeLogger.new('./tee_logger.log', 5, 1_024)
68
38
 
69
- ```ruby
70
- require 'tee_logger'
71
- TeeLogger.setup do |tee_logger|
72
- tee_logger.logdev = './hello_world.log'
73
- tee_logger.shift_age = 5
74
- tee_logger.shift_size = 1_024
75
- end
76
-
77
- TeeLogger.info 'hello' # => output console and logfile('./hello_world.log')
78
- TeeLogger.console_info 'hello' # => output console only
79
- TeeLogger.logger_info 'hello' # => output logfile only('./hello_world.log')
80
- ```
39
+ tl.debug(:progname) { 'hello world' }
40
+ tl.progname = 'App'
41
+ tl.debug('hello tee_logger')
42
+
43
+ # console only
44
+ tl.console.info('console only')
81
45
 
82
- setup item is Logger.new arguments.
83
- - logdev
84
- - shift_age
85
- - shift_size
46
+ # logfile only
47
+ tl.logger.info('logger only')
48
+ ```
86
49
 
50
+ # TODO feature
51
+ ```
52
+ # disable and enable console output
53
+ tl.disable(:console)
54
+ tl.info 'this message is logfile only'
55
+ tl.enable(:console)
56
+ tl.info 'this message is logfile and console'
57
+
58
+ # disable and enable logfile output
59
+ tl.disable(:logger)
60
+ tl.info 'this message is consle only'
61
+ tl.enable(:logger)
62
+ tl.info 'this message is logfile and console'
63
+ ```
87
64
 
88
65
  ## Development
89
66
 
@@ -93,7 +70,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
93
70
 
94
71
  ## Contributing
95
72
 
96
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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.
73
+ 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.
97
74
 
98
75
 
99
76
  ## License
@@ -1,11 +1,7 @@
1
1
  require 'logger'
2
2
 
3
- # main
3
+ # namespace
4
4
  module TeeLogger
5
- # TODO: defined by setup method, etc ...
6
- DEFAULT_FILE = './tee_logger.log'
7
- LOGGING_METHODS = %i(debug info warn error fatal).freeze
8
-
9
5
  # base class
10
6
  class Base
11
7
  attr_reader :logger, :console
@@ -15,18 +11,43 @@ module TeeLogger
15
11
  @console = Logger.new(STDOUT)
16
12
  end
17
13
 
14
+ # logging methods.
18
15
  LOGGING_METHODS.each do |method_name|
19
- define_method(method_name) do |progname = nil, &block|
20
- @logger.send(method_name, progname, &block)
21
- @console.send(method_name, progname, &block)
16
+ define_method(name) do |progname = nil, &block|
17
+ @logger.send(name, progname, &block)
18
+ @console.send(name, progname, &block)
22
19
  end
20
+ end
23
21
 
24
- define_method("#{method_name}?") do
25
- @logger.send("#{method_name}?")
26
- @console.send("#{method_name}?")
22
+ # check logging level methods.
23
+ LOGGING_METHODS.map { |v| "#{v}?" }
24
+ define_method(name) do
25
+ @logger.send(name)
26
+ @console.send(name)
27
27
  end
28
28
  end
29
29
 
30
+ # TODO: Implement
31
+ def disable(target)
32
+ # undef_method, remove_method ....
33
+ end
34
+
35
+ # TODO: Implement
36
+ def enable(target)
37
+ # undef_method, remove_method ....
38
+ end
39
+
40
+ def progname
41
+ # TODO: which?
42
+ # @logger.progname
43
+ @console.progname
44
+ end
45
+
46
+ def progname=(name = nil)
47
+ @logger.progname = name
48
+ @console.progname = name
49
+ end
50
+
30
51
  def close
31
52
  @logger.close
32
53
  # @console.close
@@ -0,0 +1,7 @@
1
+ require 'logger'
2
+
3
+ # namespace
4
+ module TeeLogger
5
+ DEFAULT_FILE = './tee_logger.log'
6
+ LOGGING_METHODS = %i(debug info warn error fatal).freeze
7
+ end
@@ -1,4 +1,4 @@
1
- # main
1
+ # namespace
2
2
  module TeeLogger
3
- VERSION = '1.1.0'
3
+ VERSION = '2.0.0'
4
4
  end
data/lib/tee_logger.rb CHANGED
@@ -1,71 +1,44 @@
1
1
  require 'tee_logger/version'
2
+ require 'tee_logger/constants'
2
3
  require 'tee_logger/base'
3
4
 
4
- # main
5
- module TeeLogger
6
- @logdev = DEFAULT_FILE
7
- @shift_age = 0
8
- @shift_size = 1_048_576
9
-
10
- # @ref https://github.com/railsconfig/config/blob/master/lib/config.rb#L18
11
- @_run_once = false
12
- def self.setup
13
- return base_logger if @_run_once
14
- define_singleton_methods_for_setup
5
+ require 'forwardable'
15
6
 
16
- yield(self) if block_given?
17
- @_run_once = true
18
-
19
- define_singleton_methods_for_logging
20
- define_singleton_methods_for_logging_with_prefix
21
- base_logger
7
+ # namespace
8
+ module TeeLogger
9
+ # shortcut for TeeLogger::TeeLogger.new
10
+ def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
11
+ TeeLogger.new(logdev, shift_age, shift_size)
22
12
  end
23
13
 
24
- class << self
25
- private
14
+ class TeeLogger
15
+ extend Forwardable
26
16
 
27
- def define_singleton_methods_for_setup
28
- %i(logdev shift_age shift_size).each do |name|
29
- define_singleton_method(name) do
30
- instance_variable_get("@#{name}".to_sym)
31
- end
32
- # private_class_method name
17
+ attr_reader :logger, :console
33
18
 
34
- define_singleton_method("#{name}=") do |arg|
35
- instance_variable_set("@#{name}".to_sym, arg)
36
- end
37
- # private_class_method "#{name}=".to_sym
38
- end
19
+ def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
20
+ @base_logger = Base.new(logdev, shift_age, shift_size)
21
+ @logger = @base_logger.logger
22
+ @console = @base_logger.console
39
23
  end
40
24
 
41
- def base_logger
42
- @base_logger ||= Base.new(logdev, shift_age, shift_size)
43
- end
25
+ # logging methods.
26
+ def_delegators :@base_logger, *LOGGING_METHODS
44
27
 
45
- def define_singleton_methods_for_logging
46
- LOGGING_METHODS.each do |name|
47
- define_singleton_method(name) do |progname = nil, &block|
48
- base_logger.send(name, progname, &block)
49
- end
28
+ # check logging level methods.
29
+ def_delegators :@base_logger, *LOGGING_METHODS.map { |v| "#{v}?" }
50
30
 
51
- define_singleton_method("#{name}?") do
52
- base_logger.send("#{name}?")
53
- end
54
- end
55
- end
31
+ # others.
32
+ def_delegators :@base_logger, :progname, :progname=
56
33
 
57
- def define_singleton_methods_for_logging_with_prefix
58
- %i(logger console).each do |pre|
59
- LOGGING_METHODS.each do |name|
60
- define_singleton_method("#{pre}_#{name}") do |progname = nil, &block|
61
- base_logger.send(pre).send(name, progname, &block)
62
- end
34
+ # TODO: Implement
35
+ # def_delegators :@base_logger, :datetime_format, :datetime_format=
36
+ # def_delegators :@base_logger, :formatter, :formatter=
63
37
 
64
- define_singleton_method("#{pre}_#{name}?") do
65
- base_logger.send(pre).send("#{name}?")
66
- end
67
- end
68
- end
69
- end
38
+ # TODO: Implement
39
+ # def_delegator :@base_logger, :close
40
+ # def_delegators :@base_logger, :level, :sev_threshold
41
+ # def_delegators :@base_logger, :add, :log
42
+ # def_delegators :@base_logger, :unknown, :unknown?
70
43
  end
71
44
  end
data/tee_logger.gemspec CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'tee_logger/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "tee_logger"
7
+ spec.name = 'tee_logger'
8
8
  spec.version = TeeLogger::VERSION
9
- spec.authors = ["k-ta-yamada"]
10
- spec.email = ["key.luvless@gmail.com"]
9
+ spec.authors = ['k-ta-yamada']
10
+ spec.email = ['key.luvless@gmail.com']
11
11
 
12
- spec.summary = %q{logging to file and standard output}
13
- spec.description = %q{logging to file and standard output}
12
+ spec.summary = 'logging to file and standard output'
13
+ spec.description = 'logging to file and standard output'
14
14
  spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
25
 
26
26
  spec.add_development_dependency 'pry'
27
27
  spec.add_development_dependency 'pry-doc'
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: 1.1.0
4
+ version: 2.0.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-07 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,6 +126,7 @@ files:
126
126
  - bin/setup
127
127
  - lib/tee_logger.rb
128
128
  - lib/tee_logger/base.rb
129
+ - lib/tee_logger/constants.rb
129
130
  - lib/tee_logger/version.rb
130
131
  - tee_logger.gemspec
131
132
  homepage: https://github.com/k-ta-yamada/tee_logger