logger-ltsv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logger-ltsv.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 tnakamura
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.
@@ -0,0 +1,48 @@
1
+ # logger-ltsv
2
+
3
+ A LTSV logger.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'logger-ltsv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install logger-ltsv
18
+
19
+ ## Usage
20
+
21
+ ### Logger::LTSVLogger
22
+
23
+ ```ruby
24
+ require "logger"
25
+ require "logger/ltsv"
26
+
27
+ logger = Logger.new(STDOUT)
28
+ logger.formatter = Logger::LTSVLogger.new
29
+ logger.info("foobar")
30
+ ```
31
+
32
+ ### LTSVLogger
33
+
34
+ ```ruby
35
+ require "logger/ltsv"
36
+
37
+ logger = LTSVLogger.new(STDOUT)
38
+ logger.info("foobar")
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ require "logger"
3
+ require "logger/ltsv/version"
4
+
5
+ class Logger
6
+ class LTSVFormatter < ::Logger::Formatter
7
+ def call(severity, datetime, progname, message)
8
+ raw = [
9
+ "severity:#{severity}",
10
+ "datetime:#{datetime}",
11
+ ]
12
+
13
+ if progname
14
+ raw << "progname:#{progname}"
15
+ end
16
+
17
+ case message
18
+ when Hash
19
+ message.each do |key, value|
20
+ raw << "#{key}:#{value}"
21
+ end
22
+ else
23
+ raw << "message:#{message}"
24
+ end
25
+
26
+ ltsv = raw.join("\t") + "\n"
27
+ ltsv
28
+ end
29
+ end
30
+ end
31
+
32
+ class LTSVLogger < ::Logger
33
+ def initialize(*args)
34
+ super
35
+ @formatter = ::Logger::LTSVFormatter.new
36
+ end
37
+ end
38
+
@@ -0,0 +1,5 @@
1
+ class Logger
2
+ module LTSV
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logger/ltsv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logger-ltsv"
8
+ spec.version = Logger::LTSV::VERSION
9
+ spec.authors = ["tnakamura"]
10
+ spec.email = ["griefworker@gmail.com"]
11
+ spec.description = %q{LTSV logger}
12
+ spec.summary = %q{LTSV logger}
13
+ spec.homepage = "https://github.com/tnakamura/logger-ltsv"
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
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ require_relative "spec_helper"
3
+ require "date"
4
+
5
+ describe Logger::LTSVFormatter do
6
+ describe "#call" do
7
+ before do
8
+ @formatter = ::Logger::LTSVFormatter.new
9
+ @today = Date.today
10
+ end
11
+
12
+ context "デフォルト" do
13
+ it "LTSV 形式に整形できる" do
14
+ actual = @formatter.call("Warn", @today, "Foo", "Bar")
15
+ expect(actual).to eq("severity:Warn\tdatetime:#{@today}\tprogname:Foo\tmessage:Bar\n")
16
+ end
17
+ end
18
+
19
+ context "ハッシュを指定したとき" do
20
+ it "LTSV 形式に整形できる" do
21
+ actual = @formatter.call("Warn", @today, "Foo", {
22
+ name:"Bar", age:16
23
+ })
24
+ expect(actual).to eq("severity:Warn\tdatetime:#{@today}\tprogname:Foo\tname:Bar\tage:16\n")
25
+ end
26
+ end
27
+
28
+ context "pragname が nil のとき" do
29
+ it "pragname が省略されるべき" do
30
+ actual = @formatter.call("Warn", @today, nil, "Bar")
31
+ expect(actual).to eq("severity:Warn\tdatetime:#{@today}\tmessage:Bar\n")
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ require_relative "spec_helper"
3
+ require "date"
4
+ require "stringio"
5
+
6
+ describe LTSVLogger do
7
+ before do
8
+ @output = StringIO.new
9
+ @logger = LTSVLogger.new(@output)
10
+ end
11
+
12
+ describe "#formatter" do
13
+ it "Logger::LTSVFormatter を返す" do
14
+ expect(@logger.formatter).to be_an_instance_of(Logger::LTSVFormatter)
15
+ end
16
+ end
17
+
18
+ describe "#info" do
19
+ it "LTSV 形式でログを出力できる" do
20
+ @logger.info("Test")
21
+
22
+ @output.seek(0)
23
+ ltsv = @output.read.strip.split("\t")
24
+ expect(ltsv.include?("severity:INFO")).to be_true
25
+ expect(ltsv.include?("message:Test")).to be_true
26
+ end
27
+
28
+ it "ハッシュを LTSV で出力できる" do
29
+ @logger.info(name:"Foo", age:16)
30
+
31
+ @output.seek(0)
32
+ ltsv = @output.read.strip.split("\t")
33
+ expect(ltsv.include?("severity:INFO")).to be_true
34
+ expect(ltsv.include?("name:Foo")).to be_true
35
+ expect(ltsv.include?("age:16")).to be_true
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ require "rspec"
5
+ require "logger/ltsv"
6
+ require "rspec/autorun"
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logger-ltsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tnakamura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &21949728 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21949728
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &21949224 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21949224
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &21948120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21948120
47
+ description: LTSV logger
48
+ email:
49
+ - griefworker@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/logger/ltsv.rb
60
+ - lib/logger/ltsv/version.rb
61
+ - logger-ltsv.gemspec
62
+ - spec/ltsv_formatter_spec.rb
63
+ - spec/ltsv_logger_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/tnakamura/logger-ltsv
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: -404674161
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -404674161
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.16
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: LTSV logger
96
+ test_files:
97
+ - spec/ltsv_formatter_spec.rb
98
+ - spec/ltsv_logger_spec.rb
99
+ - spec/spec_helper.rb