ltsv_ng 0.0.1

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: a521d1eff162a25c8a622ad1a8cf2c278863f11a
4
+ data.tar.gz: 41efc2f061b98220ca8d2542d02ecd55904f15c5
5
+ SHA512:
6
+ metadata.gz: 652dbbbf133f5c4f90a759daa02ec89f5a8da1a3c04660422bd375329d1c35261fcd8ea645e30aa99c28b9dd1ed3c2641ce33cc067b66c8e6507f265b89f187c
7
+ data.tar.gz: d7f67a464468babde48597ed9f8082a0c51d653a59766fed80b870d06169df62c8b9fc985bcd6f29c1de6b389ce92abcfdce814f96994c5e46eab7c53aecf147
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /vendor/
16
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ltsv_ng.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 hirocaster
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,53 @@
1
+ # LtsvNg
2
+
3
+ [LTSV](http://ltsv.org/) logger for Ruby application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ltsv_ng'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ltsv_ng
20
+
21
+ ## Usage
22
+
23
+ ### for Rails
24
+
25
+ in `config/environments/production.rb`
26
+
27
+ ```ruby
28
+ Rails.application.configure do
29
+
30
+ (snip)
31
+
32
+ logger = LtsvNg::Logger.new(Rails.root.join("log/#{Rails.env}.log"))
33
+ config.logger = logger
34
+
35
+ (snip)
36
+
37
+ end
38
+ ```
39
+
40
+ ### Sample log
41
+
42
+ ```ruby
43
+ Rails.logger.info "foobar" # => level:INFO time:2015-08-05 00:44:31 +0900 msg:foobar
44
+ Rails.logger.info id: 123, name: "alice" # => level:INFO time:2015-08-05 00:46:56 +0900 id:123 name:alice
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/hirocaster/ltsv_ng/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ module LtsvNg
2
+ class Formatter < ::Logger::Formatter
3
+ def call(severity, timestamp, progname, msg)
4
+ raws = ["level:#{ severity }", "time:#{ timestamp }"]
5
+ case msg
6
+ when Hash
7
+ raws = msg.inject(raws) { |h, (key, value)| h << "#{key}:#{value}"; h }
8
+ when String
9
+ raws << "msg:#{ msg }"
10
+ end
11
+ "#{raws.join("\t")}\n"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module LtsvNg
2
+ class Logger < ::Logger
3
+ def initialize(*args)
4
+ super
5
+ @formatter = LtsvNg::Formatter.new
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module LtsvNg
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ltsv_ng.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "ltsv_ng/version"
2
+
3
+ require "logger"
4
+ require "ltsv_ng/logger"
5
+ require "ltsv_ng/formatter"
6
+
7
+ module LtsvNg
8
+ # Your code goes here...
9
+ end
data/ltsv_ng.gemspec ADDED
@@ -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 'ltsv_ng/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ltsv_ng"
8
+ spec.version = LtsvNg::VERSION
9
+ spec.authors = ["hirocaster"]
10
+ spec.email = ["hohtsuka@gmail.com"]
11
+ spec.summary = %q{LTSV format logger.}
12
+ spec.description = %q{LTSV logger for Ruby application.}
13
+ spec.homepage = "https://github.com/hirocaster/ltsv_ng"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe "LtsvNg::Formatter" do
4
+ let(:time) { Time.now }
5
+ let(:formatter) { LtsvNg::Formatter.new }
6
+
7
+ describe "#call" do
8
+ context "String data log" do
9
+ it "returns LTSV Format text" do
10
+ text = formatter.call("INFO", time, nil, "foobar")
11
+ expect(text).to eq "level:INFO\ttime:#{time}\tmsg:foobar\n"
12
+ end
13
+ end
14
+
15
+ context "Hash data log" do
16
+ it "returns LTSV Format text" do
17
+ text = formatter.call("INFO", time, nil, { id: 123, name: "foobar"})
18
+ expect(text).to eq "level:INFO\ttime:#{time}\tid:123\tname:foobar\n"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe "LtsvNg::Logger" do
4
+ before do
5
+ @output = StringIO.new
6
+ @logger = LtsvNg::Logger.new(@output)
7
+ end
8
+
9
+ describe "#formatter" do
10
+ it "returns Logger::LtsvNg::Formatter" do
11
+ expect(@logger.formatter).to be_an_instance_of(LtsvNg::Formatter)
12
+ end
13
+ end
14
+
15
+ describe "#info" do
16
+ it "returns info log by String Text" do
17
+ @logger.info("Test")
18
+
19
+ @output.seek(0)
20
+ ltsv = @output.read.strip.split("\t")
21
+ expect(ltsv).to include("level:INFO")
22
+ expect(ltsv).to include("msg:Test")
23
+ end
24
+
25
+ it "returns info log by Hash" do
26
+ @logger.info(id: 123, name: "foobar")
27
+ @output.seek(0)
28
+ ltsv = @output.read.strip.split("\t")
29
+ expect(ltsv).to include("level:INFO")
30
+ expect(ltsv).to include("id:123")
31
+ expect(ltsv).to include("name:foobar")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,98 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
97
+
98
+ require "ltsv_ng"
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ltsv_ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hirocaster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: LTSV logger for Ruby application.
56
+ email:
57
+ - hohtsuka@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ltsv_ng.rb
68
+ - lib/ltsv_ng/formatter.rb
69
+ - lib/ltsv_ng/logger.rb
70
+ - lib/ltsv_ng/version.rb
71
+ - ltsv_ng.gemspec
72
+ - spec/formatter_spec.rb
73
+ - spec/logger_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/hirocaster/ltsv_ng
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: LTSV format logger.
99
+ test_files:
100
+ - spec/formatter_spec.rb
101
+ - spec/logger_spec.rb
102
+ - spec/spec_helper.rb