ougai 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +119 -0
- data/Rakefile +6 -0
- data/lib/ougai.rb +93 -0
- data/lib/ougai/version.rb +3 -0
- data/ougai.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce8d26f420ba36c7f5549d588a7756b3a3589f47
|
4
|
+
data.tar.gz: c3e1a64adca117d2e919481b312b6115c0b8c316
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35ba1dd4e1a0dc58192f294077b6dbc00a99c26bc49680bb0935297aa756bdaa321eb19cd8f8bb6b3470baf825c25f3c67fa211d5af1507d1f07a03acaf2d2eb
|
7
|
+
data.tar.gz: 28346ef88a79b9fe9ffe6233214b9bf06752ed60d1ee4d017035426bd688e6532cca010f74c1b40a1028e17b2b4184e099c038b4ff6e9943006e9077e9e2a8a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Toshimitsu Takahashi
|
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,119 @@
|
|
1
|
+
Ougai
|
2
|
+
=====
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/tilfin/ougai.svg?branch=master)](https://travis-ci.org/tilfin/ougai)
|
5
|
+
|
6
|
+
A JSON logger is compatible with [bunyan](https://github.com/trentm/node-bunyan) for Node.js
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'ougai'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ gem install ougai
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
**Ougai::Logger** is sub-class of original [Logger](https://docs.ruby-lang.org/ja/latest/class/Logger.html) in Ruby.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'rubygems'
|
34
|
+
require 'ougai'
|
35
|
+
|
36
|
+
logger = Ougai::Logger.new(STDOUT)
|
37
|
+
```
|
38
|
+
|
39
|
+
### log only message
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
logger.info('Information!')
|
43
|
+
```
|
44
|
+
|
45
|
+
```json
|
46
|
+
{"name":"main","hostname":"mint","pid":14607,"level":30,"time":"2016-10-16T22:26:48.835+09:00","v":0,"msg":"Information!"}
|
47
|
+
```
|
48
|
+
|
49
|
+
### log with a message and custom data
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
logger.debug('Debugging', data_id: 1, data_flag: true)
|
53
|
+
logger.debug('Debug!', custom_data: { id: 1, name: 'something' })
|
54
|
+
```
|
55
|
+
|
56
|
+
```json
|
57
|
+
{"name":"main","hostname":"mint","pid":14607,"level":20,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Debugging","custom_data":{"id":1,"name":"something"}}
|
58
|
+
{"name":"main","hostname":"mint","pid":14607,"level":20,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Debug!","data_id":1,"data_flag":true}
|
59
|
+
```
|
60
|
+
|
61
|
+
### log with a message and an exception
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
begin
|
65
|
+
raise StandardError, 'fatal error'
|
66
|
+
rescue => ex
|
67
|
+
logger.fatal('Unexpected!', ex)
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
```json
|
72
|
+
{"name":"main","hostname":"mint","pid":14607,"level":60,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Unexpected!","err":{"name":"StandardError","message":"fatal error","stack":"main.rb:12:in `<main>'"}}
|
73
|
+
```
|
74
|
+
|
75
|
+
### log with a message, an exception and custom data
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
begin
|
79
|
+
1 / 0
|
80
|
+
rescue => ex
|
81
|
+
logger.error('Caught error', ex, reason: 'zero spec')
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
```json
|
86
|
+
{"name":"main","hostname":"mint","pid":14607,"level":50,"time":"2016-10-16T22:26:48.836+09:00","v":0,"msg":"Caught error","err":{"name":"ZeroDivisionError","message":"divided by 0","stack":"main.rb:18:in `/'\n ...'"},"reason":"zero spec"}
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
## View log by node-bunyan
|
91
|
+
|
92
|
+
Install [bunyan](https://github.com/trentm/node-bunyan) via NPM
|
93
|
+
|
94
|
+
```
|
95
|
+
$ npm install -g bunyan
|
96
|
+
```
|
97
|
+
|
98
|
+
Pass a log file to command `bunyan`
|
99
|
+
|
100
|
+
```
|
101
|
+
$ bunyan output.log
|
102
|
+
[2016-10-16T22:26:48.835+09:00] INFO: main/14607 on mint: Info message!
|
103
|
+
[2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debugging (data_id=1, data_flag=true)
|
104
|
+
[2016-10-16T22:26:48.836+09:00] DEBUG: main/14607 on mint: Debug!
|
105
|
+
custom_data: {
|
106
|
+
"id": 1,
|
107
|
+
"name": "something"
|
108
|
+
}
|
109
|
+
[2016-10-16T22:26:48.836+09:00] FATAL: main/14607 on mint: Unexpected!
|
110
|
+
main.rb:12:in `<main>'
|
111
|
+
[2016-10-16T22:26:48.836+09:00] ERROR: main/14607 on mint: Caught error (reason="z
|
112
|
+
main.rb:18:in `/'
|
113
|
+
main.rb:18:in `<main>'
|
114
|
+
```
|
115
|
+
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
[MIT](LICENSE.txt)
|
data/Rakefile
ADDED
data/lib/ougai.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "ougai/version"
|
2
|
+
require 'logger'
|
3
|
+
require 'socket'
|
4
|
+
require 'time'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Ougai
|
8
|
+
class Logger < Logger
|
9
|
+
def initialize(*args)
|
10
|
+
super(*args)
|
11
|
+
run_filename = File.basename($0, ".rb")
|
12
|
+
hostname = Socket.gethostname
|
13
|
+
@formatter = proc do |severity, time, progname, data|
|
14
|
+
JSON.generate({
|
15
|
+
name: progname || run_filename,
|
16
|
+
hostname: hostname,
|
17
|
+
pid: $$,
|
18
|
+
level: to_level(severity),
|
19
|
+
time: time.iso8601(3),
|
20
|
+
v: 0
|
21
|
+
}.merge(data)) + "\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def debug(message, ex = nil, data = {})
|
26
|
+
super(to_item(message, ex, data))
|
27
|
+
end
|
28
|
+
|
29
|
+
def info(message, ex = nil, data = {})
|
30
|
+
super(to_item(message, ex, data))
|
31
|
+
end
|
32
|
+
|
33
|
+
def warn(message, ex = nil, data = {})
|
34
|
+
super(to_item(message, ex, data))
|
35
|
+
end
|
36
|
+
|
37
|
+
def error(message, ex = nil, data = {})
|
38
|
+
super(to_item(message, ex, data))
|
39
|
+
end
|
40
|
+
|
41
|
+
def fatal(message, ex = nil, data = {})
|
42
|
+
super(to_item(message, ex, data))
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def to_item(msg, ex, data)
|
48
|
+
item = {}
|
49
|
+
if ex.nil? && msg.is_a?(Exception)
|
50
|
+
item[:msg] = ex.to_s
|
51
|
+
item[:err] = serialize_ex(ex)
|
52
|
+
elsif ex
|
53
|
+
item[:msg] = msg
|
54
|
+
if ex.is_a?(Hash)
|
55
|
+
item.merge!(ex)
|
56
|
+
elsif ex.is_a?(Exception)
|
57
|
+
item[:err] = serialize_ex(ex)
|
58
|
+
item.merge!(data)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
item[:msg] = msg
|
62
|
+
item.merge!(data)
|
63
|
+
end
|
64
|
+
item
|
65
|
+
end
|
66
|
+
|
67
|
+
def serialize_ex(ex)
|
68
|
+
err = {
|
69
|
+
name: ex.class.name,
|
70
|
+
message: ex.to_s
|
71
|
+
}
|
72
|
+
if ex.backtrace
|
73
|
+
err[:stack] = ex.backtrace.join("\n ")
|
74
|
+
end
|
75
|
+
err
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_level(severity)
|
79
|
+
case severity
|
80
|
+
when 'INFO'
|
81
|
+
30
|
82
|
+
when 'WARN'
|
83
|
+
40
|
84
|
+
when 'ERROR'
|
85
|
+
50
|
86
|
+
when 'FATAL'
|
87
|
+
60
|
88
|
+
else # DEBUG
|
89
|
+
20
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/ougai.gemspec
ADDED
@@ -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 'ougai/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ougai"
|
8
|
+
spec.version = Ougai::VERSION
|
9
|
+
spec.authors = ["Toshimitsu Takahashi"]
|
10
|
+
spec.email = ["toshi@tilfin.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{JSON logger compatible node-bunyan.}
|
13
|
+
spec.description = %q{JSON logger compatible bunyan for Node.js}
|
14
|
+
spec.homepage = "https://github.com/tilfin/ougai"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ougai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toshimitsu Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-16 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: JSON logger compatible bunyan for Node.js
|
56
|
+
email:
|
57
|
+
- toshi@tilfin.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/ougai.rb
|
70
|
+
- lib/ougai/version.rb
|
71
|
+
- ougai.gemspec
|
72
|
+
homepage: https://github.com/tilfin/ougai
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.1.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: JSON logger compatible node-bunyan.
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|