tee_logger 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9058b6e01266bfb96d6729b17ea1dc97cb74cc94
4
+ data.tar.gz: 706036b627118814ad9f32842c5f836cdb9920ae
5
+ SHA512:
6
+ metadata.gz: f35e33f05d6bcf14ac60949f60c781373cac5bbd93643cd9e398f9d691578e9911fe3e4e14923efff57282de4668663b62208406e9890760a6a206c0ee23a5a3
7
+ data.tar.gz: 8bc9f86022717a8a61319eab2585fb84d176762938e9279aa00c2e44d1e365ec5bd6ccc2cdada778583150192954f196b895b1c3259322b23a6a0e47a990ac79
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /vendor
12
+ tee_logger.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tee_logger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 k-ta-yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # TeeLogger
2
+
3
+ logging to logfile and standard output
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tee_logger'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tee_logger
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ 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
+
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.
68
+
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
+ ```
81
+
82
+ setup item is Logger.new arguments.
83
+ - logdev
84
+ - shift_age
85
+ - shift_size
86
+
87
+
88
+ ## Development
89
+
90
+ 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.
91
+
92
+ 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).
93
+
94
+ ## Contributing
95
+
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.
97
+
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
102
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tee_logger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ require 'logger'
2
+
3
+ # main
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
+ # base class
10
+ class Base
11
+ attr_reader :logger, :console
12
+
13
+ def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
14
+ @logger = Logger.new(logdev, shift_age, shift_size)
15
+ @console = Logger.new(STDOUT)
16
+ end
17
+
18
+ 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)
22
+ end
23
+
24
+ define_method("#{method_name}?") do
25
+ @logger.send("#{method_name}?")
26
+ @console.send("#{method_name}?")
27
+ end
28
+ end
29
+
30
+ def close
31
+ @logger.close
32
+ # @console.close
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ # main
2
+ module TeeLogger
3
+ VERSION = '1.0.0'
4
+ end
data/lib/tee_logger.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'tee_logger/version'
2
+ require 'tee_logger/base'
3
+
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
+
15
+ yield(self) if block_given?
16
+ @_run_once = true
17
+
18
+ define_singleton_methods_for_setup
19
+ define_singleton_methods_for_logging
20
+ define_singleton_methods_for_logging_with_prefix
21
+ base_logger
22
+ end
23
+
24
+ class << self
25
+ private
26
+
27
+ def base_logger
28
+ @base_logger ||= Base.new(logdev, shift_age, shift_size)
29
+ end
30
+
31
+ def define_singleton_methods_for_setup
32
+ %i(logdev shift_age shift_size).each do |name|
33
+ define_singleton_method(name) do
34
+ instance_variable_get("@#{name}".to_sym)
35
+ end
36
+ private_class_method name
37
+
38
+ define_singleton_method("#{name}=") do |arg|
39
+ instance_variable_set("@#{name}".to_sym, arg)
40
+ end
41
+ private_class_method "#{name}=".to_sym
42
+ end
43
+ end
44
+
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
50
+
51
+ define_singleton_method("#{name}?") do
52
+ base_logger.send("#{name}?")
53
+ end
54
+ end
55
+ end
56
+
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
63
+
64
+ define_singleton_method("#{pre}_#{name}?") do
65
+ base_logger.send(pre).send("#{name}?")
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,30 @@
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 = %q{logging to file and standard output}
13
+ spec.description = %q{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
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tee_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - k-ta-yamada
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-theme
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: logging to file and standard output
112
+ email:
113
+ - key.luvless@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/tee_logger.rb
128
+ - lib/tee_logger/base.rb
129
+ - lib/tee_logger/version.rb
130
+ - tee_logger.gemspec
131
+ homepage: https://github.com/k-ta-yamada/tee_logger
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.8
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: logging to file and standard output
155
+ test_files: []
156
+ has_rdoc: