ougai 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/lib/ougai.rb +24 -12
- data/lib/ougai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b0465e90dbafc2f753aa9913eaf7e7b3201af61
|
4
|
+
data.tar.gz: c1a31078a887b752c8a345b205dae87524457e0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8714ecf3b6a701a498ef18d1c224b2897a98513b9d4ff59921c845ec2040dccee448af9b2579d32446577d02f26b41bb21fb29ab7f90f834733cd88cd522d2b
|
7
|
+
data.tar.gz: 36dfd041ba4a4485b049d67babb112f90f5383e25ac6bb3f114681d2beb14e696fafdad6f9e67c272477f8bafc9ba7a3fea617036fbfea0ee08f90ce9b88da22
|
data/README.md
CHANGED
@@ -47,6 +47,33 @@ logger.info('Information!')
|
|
47
47
|
{"name":"main","hostname":"mint","pid":14607,"level":30,"time":"2016-10-16T22:26:48.835+09:00","v":0,"msg":"Information!"}
|
48
48
|
```
|
49
49
|
|
50
|
+
### log only a data
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
logger.info({
|
54
|
+
msg: 'Request', method: 'GET', path: '/login',
|
55
|
+
format: 'html', controller: 'LoginController',
|
56
|
+
action: 'new', status: 200
|
57
|
+
})
|
58
|
+
logger.debug(user: { name: 'Taro', age: 19 })
|
59
|
+
```
|
60
|
+
|
61
|
+
```json
|
62
|
+
{"name":"main","hostname":"mint","pid":9044,"level":30,"time":"2016-10-28T17:58:53.668+09:00","v":0,"msg":"Request","method":"GET","path":"/login","format":"html","controller":"LoginController","action":"new","status":200}
|
63
|
+
{"name":"main","hostname":"mint","pid":9044,"level":20,"time":"2016-10-28T17:58:53.668+09:00","v":0,"msg":"No message","user":{"name":"Taro","age":19}}
|
64
|
+
```
|
65
|
+
|
66
|
+
If a data does not contain `msg` field, msg is set `default_message` attribute value of a Logger. its default is 'No message'.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
logger.default_message = 'User dump'
|
70
|
+
logger.debug(user: { name: 'Taro', age: 19 })
|
71
|
+
```
|
72
|
+
|
73
|
+
```json
|
74
|
+
{"name":"main","hostname":"mint","pid":9303,"level":20,"time":"2016-10-28T18:03:50.118+09:00","v":0,"msg":"User dump","user":{"name":"Taro","age":19}}
|
75
|
+
```
|
76
|
+
|
50
77
|
### log only an exception
|
51
78
|
|
52
79
|
```ruby
|
data/lib/ougai.rb
CHANGED
@@ -6,20 +6,14 @@ require 'json'
|
|
6
6
|
|
7
7
|
module Ougai
|
8
8
|
class Logger < Logger
|
9
|
+
attr_accessor :default_message, :app_name
|
10
|
+
|
9
11
|
def initialize(*args)
|
10
12
|
super(*args)
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
|
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
|
13
|
+
@default_message = 'No message'
|
14
|
+
@app_name = File.basename($0, ".rb")
|
15
|
+
@hostname = Socket.gethostname
|
16
|
+
@formatter = create_formatter
|
23
17
|
end
|
24
18
|
|
25
19
|
def debug(message, ex = nil, data = {})
|
@@ -42,6 +36,21 @@ module Ougai
|
|
42
36
|
super(to_item(message, ex, data))
|
43
37
|
end
|
44
38
|
|
39
|
+
protected
|
40
|
+
|
41
|
+
def create_formatter
|
42
|
+
proc do |severity, time, progname, data|
|
43
|
+
JSON.generate({
|
44
|
+
name: progname || @app_name,
|
45
|
+
hostname: @hostname,
|
46
|
+
pid: $$,
|
47
|
+
level: to_level(severity),
|
48
|
+
time: time.iso8601(3),
|
49
|
+
v: 0
|
50
|
+
}.merge(data)) + "\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
45
54
|
private
|
46
55
|
|
47
56
|
def to_item(msg, ex, data)
|
@@ -57,6 +66,9 @@ module Ougai
|
|
57
66
|
item[:err] = serialize_ex(ex)
|
58
67
|
item.merge!(data)
|
59
68
|
end
|
69
|
+
elsif msg.is_a?(Hash)
|
70
|
+
item[:msg] = @default_message unless msg.key?(:msg)
|
71
|
+
item.merge!(msg)
|
60
72
|
else
|
61
73
|
item[:msg] = msg
|
62
74
|
item.merge!(data)
|
data/lib/ougai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ougai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshimitsu Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|