ltsv_logger 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ltsv_logger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yuya.Nishida.
2
+
3
+ X11 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,49 @@
1
+ # LtsvLogger
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'ltsv_logger'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install ltsv_logger
16
+
17
+ ## Usage
18
+
19
+ ### Normal case
20
+
21
+ require "ltsv_logger"
22
+ logger = LtsvLogger.new(STDOUT)
23
+ a = 2
24
+ logger.info(message: "double a", a: a, double_a: a * 2)
25
+ logger.info("triple of a", a: a, triple_a: a * 3)
26
+ logger.info {
27
+ {message: "double a", a: a, double_a: a * 2}
28
+ }
29
+ logger.info {
30
+ ["triple a", a: a, triple_a: a * 3]
31
+ }
32
+
33
+ ## License
34
+
35
+ X11 License.
36
+ See LICENSE.txt for more information.
37
+
38
+ ### Why X11 License?
39
+
40
+ You can see following URI:
41
+ http://www.gnu.org/licenses/license-list.en.html#X11License
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,61 @@
1
+ require "forwardable"
2
+ require "logger"
3
+ require "time"
4
+ require "ltsv"
5
+
6
+ class LtsvLogger
7
+ extend Forwardable
8
+ include Logger::Severity
9
+
10
+ VERSION = "0.0.0"
11
+
12
+ def initialize(*args)
13
+ @logger = Logger.new(*args)
14
+ end
15
+
16
+ def_delegators :@logger,
17
+ :close, :level, :level=,
18
+ :debug?, :info?, :warn?, :error?, :fatal?
19
+
20
+ def debug(message_or_log_hash = nil, log_hash = nil, &block)
21
+ add(DEBUG, message_or_log_hash, log_hash, &block)
22
+ end
23
+
24
+ def info(message_or_log_hash = nil, log_hash = nil, &block)
25
+ add(INFO, message_or_log_hash, log_hash, &block)
26
+ end
27
+
28
+ def warn(message_or_log_hash = nil, log_hash = nil, &block)
29
+ add(WARN, message_or_log_hash, log_hash, &block)
30
+ end
31
+
32
+ def error(message_or_log_hash = nil, log_hash = nil, &block)
33
+ add(ERROR, message_or_log_hash, log_hash, &block)
34
+ end
35
+
36
+ def fatal(message_or_log_hash = nil, log_hash = nil, &block)
37
+ add(FATAL, message_or_log_hash, log_hash, &block)
38
+ end
39
+
40
+ def add(severity, message_or_log_hash = nil, log_hash = nil, &block)
41
+ if block_given?
42
+ array_or_hash = yield
43
+ if array_or_hash.respond_to?(:to_h)
44
+ message_or_log_hash = array_or_hash
45
+ else # as an Array
46
+ message_or_log_hash, log_hash = *array_or_hash
47
+ end
48
+ end
49
+ if message_or_log_hash.respond_to?(:to_h)
50
+ output_data = message_or_log_hash.to_h
51
+ else
52
+ output_data = log_hash.to_h.merge(message: message_or_log_hash)
53
+ end
54
+ severity_string =
55
+ @logger.send(:format_severity, severity) # call private method!
56
+ output_data = output_data.merge(time: Time.now.iso8601(6),
57
+ pid: Process.pid,
58
+ severity: severity_string)
59
+ @logger << LTSV.dump(output_data)
60
+ end
61
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ltsv_logger"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ltsv_logger"
8
+ spec.version = LtsvLogger::VERSION
9
+ spec.authors = ["Yuya.Nishida."]
10
+ spec.email = ["yuya@j96.org"]
11
+ spec.description = "A logger implementation for LTSV format"
12
+ spec.summary = "A logger implementation for LTSV format"
13
+ spec.homepage = "https://github.com/nishidayuya/ltsv_logger"
14
+ spec.license = "X11"
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_dependency "ltsv", "~> 0.1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ltsv_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuya.Nishida.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ltsv
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A logger implementation for LTSV format
63
+ email:
64
+ - yuya@j96.org
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/ltsv_logger.rb
75
+ - ltsv_logger.gemspec
76
+ homepage: https://github.com/nishidayuya/ltsv_logger
77
+ licenses:
78
+ - X11
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.25
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A logger implementation for LTSV format
101
+ test_files: []
102
+ has_rdoc: