tidy_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/lib/tidy_logger.rb +59 -0
- data/lib/tidy_logger/version.rb +3 -0
- data/test/test_tidy_logger.rb +62 -0
- data/tidy_logger.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16454c5ba23f0c8f1092e362781dbb6d7b291d5e
|
4
|
+
data.tar.gz: f0a20d306e31b0e22154b953d4caabaaf7922d80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1062ea6dc380d9fbe8f69400ef2ccb6d531f15346d73b96af9bedf03ecf40d2aeed74c7fdfa6f4405b454477510e33cda791610773a4c6be95d9b63ec730b412
|
7
|
+
data.tar.gz: 7cf680f589e5e8a6c903d91a1d2c7573332174ba2aac9b4246aadab4ef810160fe127a46363f9386374da610dcea4ac6def5f1ffa9c3d0771e1f6a07d3c2039d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kenn Ejima
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TidyLogger
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tidy_logger'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tidy_logger
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/tidy_logger.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class TidyLogger < ::Logger
|
4
|
+
def initialize(*args)
|
5
|
+
super
|
6
|
+
@formatter = Formatter.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def config(options = :time_and_level)
|
10
|
+
case options
|
11
|
+
when Symbol
|
12
|
+
options = { type: options }
|
13
|
+
when Hash
|
14
|
+
options[:type] = :time_and_level if options[:type].nil?
|
15
|
+
options[:type] = :title if options[:title]
|
16
|
+
when Proc
|
17
|
+
options = { type: options }
|
18
|
+
else
|
19
|
+
raise Error, "invalid options: #{options.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
self.formatter.type = options[:type]
|
23
|
+
self.level = options[:level] || Logger::INFO
|
24
|
+
self.formatter.datetime_format = options[:datetime_format] || '%Y-%m-%dT%H:%M:%S'
|
25
|
+
self.formatter.title = options[:title]
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
class Formatter < ::Logger::Formatter
|
30
|
+
attr_accessor :type, :title
|
31
|
+
|
32
|
+
def call(severity, time, progname, msg)
|
33
|
+
case @type
|
34
|
+
when Proc
|
35
|
+
instance_exec(severity, time, progname, msg, &@type)
|
36
|
+
when :plain
|
37
|
+
"#{stringify(msg)}\n"
|
38
|
+
when :title
|
39
|
+
"[#{@title}] #{stringify(msg)}\n"
|
40
|
+
when :time
|
41
|
+
"[#{format_datetime(time)}] #{stringify(msg)}\n"
|
42
|
+
when :time_and_level
|
43
|
+
"[%s] %5s : %s\n" % [format_datetime(time), severity, stringify(msg)]
|
44
|
+
when :ltsv
|
45
|
+
raise Error, "ltsv logger only takes Hash" unless msg.is_a?(Hash)
|
46
|
+
msg.map{|k,v| "#{k}:#{v}" }.join("\t") << "\n"
|
47
|
+
else
|
48
|
+
# default stdlib logger format
|
49
|
+
"%s, [%s#%d] %5s -- %s: %s\n" % [severity[0..0], format_datetime(time), $$, severity, progname, msg2str(msg)]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def stringify(msg)
|
54
|
+
String === msg ? msg : msg.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Error = Class.new(StandardError)
|
59
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
require 'tidy_logger'
|
4
|
+
require 'stringio'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
class TestTidyLogger < MiniTest::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@io = StringIO.new
|
10
|
+
@logger = TidyLogger.new(@io)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_default_format
|
14
|
+
@logger.info 'buzz'
|
15
|
+
assert @io.string =~ /^I, \[(\S+) #\d+\] INFO -- : buzz$/, 'format mismatch'
|
16
|
+
assert_instance_of Time, Time.iso8601($1)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_skip_debug_by_default
|
20
|
+
@logger.config
|
21
|
+
@logger.debug 'buzz'
|
22
|
+
assert_equal '', @io.string
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_time_and_level
|
26
|
+
@logger.config
|
27
|
+
@logger.info 'buzz'
|
28
|
+
assert @io.string =~ /^\[(\S+)\] INFO : buzz$/, 'format mismatch'
|
29
|
+
assert_instance_of Time, Time.iso8601($1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_plain
|
33
|
+
@logger.config(:plain)
|
34
|
+
@logger.info 'buzz'
|
35
|
+
assert_equal "buzz\n", @io.string
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_title
|
39
|
+
@logger.config(:title => 'fizz')
|
40
|
+
@logger.info 'buzz'
|
41
|
+
assert_equal "[fizz] buzz\n", @io.string
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_time
|
45
|
+
@logger.config(:time)
|
46
|
+
@logger.info 'buzz'
|
47
|
+
assert @io.string =~ /^\[(\S+)\] buzz$/, 'format mismatch'
|
48
|
+
assert_instance_of Time, Time.iso8601($1)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_ltsv
|
52
|
+
@logger.config(:ltsv)
|
53
|
+
@logger.info :fizz => 1, :buzz => 2
|
54
|
+
assert_equal "fizz:1\tbuzz:2\n", @io.string
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lambda
|
58
|
+
@logger.config(lambda{|_,_,_,msg| "||do crazy stuff|| #{msg2str(msg)}\n" })
|
59
|
+
@logger.info 'buzz'
|
60
|
+
assert_equal "||do crazy stuff|| buzz\n", @io.string
|
61
|
+
end
|
62
|
+
end
|
data/tidy_logger.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tidy_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tidy_logger'
|
8
|
+
spec.version = TidyLogger::VERSION
|
9
|
+
spec.authors = ['Kenn Ejima']
|
10
|
+
spec.email = ['kenn.ejima@gmail.com']
|
11
|
+
spec.description = %q{TidyLogger: Logger on Steroids}
|
12
|
+
spec.summary = %q{TidyLogger: Logger on Steroids}
|
13
|
+
spec.homepage = 'https://github.com/kenn/tidy_logger'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tidy_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenn Ejima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-22 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 'TidyLogger: Logger on Steroids'
|
42
|
+
email:
|
43
|
+
- kenn.ejima@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/tidy_logger.rb
|
55
|
+
- lib/tidy_logger/version.rb
|
56
|
+
- test/test_tidy_logger.rb
|
57
|
+
- tidy_logger.gemspec
|
58
|
+
homepage: https://github.com/kenn/tidy_logger
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: 'TidyLogger: Logger on Steroids'
|
82
|
+
test_files:
|
83
|
+
- test/test_tidy_logger.rb
|
84
|
+
has_rdoc:
|