ltsv_log_formatter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +10 -3
- data/lib/ltsv_log_formatter.rb +7 -1
- data/ltsv_log_formatter.gemspec +1 -1
- data/spec/ltsv_log_formatter_spec.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e184e787ef1f75e5af51681a1d84f7d796d017c
|
4
|
+
data.tar.gz: 1f9a3afe5bff72ef7f366814209c55857d2afda5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba24abdbdd5c94a3bbd64acb8e4db34648d66cef39802ae8c9c7d8e2f8d7eafd64b7972d35c91f2d80bd0bf03a5fdd79f685356f10889cc0a29c42f5134f0b72
|
7
|
+
data.tar.gz: d2a6ad4d752a905b3b0516aa5e88f70fadf0a950c13f0c42217d15f40a1ad95ff4ae25e95164c507db1d714c6dd8f03a01ab752c57cb36f1e2bb84c77bb0b659
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -35,8 +35,8 @@ config.logger.formatter = LtsvLogFormatter.new
|
|
35
35
|
Passing a hash parameter:
|
36
36
|
|
37
37
|
```
|
38
|
-
irb> logger.info({foo: "bar"})
|
39
|
-
time:20150423T00:00:00+09:00\tlevel:INFO\tfoo:bar
|
38
|
+
irb> logger.info({foo: "foo", bar: "bar"})
|
39
|
+
time:20150423T00:00:00+09:00\tlevel:INFO\tfoo:foo\tbar:bar
|
40
40
|
```
|
41
41
|
|
42
42
|
Passing a string parameter: `message` key is used as default
|
@@ -46,13 +46,20 @@ irb> logger.info("foo")
|
|
46
46
|
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo
|
47
47
|
```
|
48
48
|
|
49
|
-
|
49
|
+
NOTE1: Notice that the line feed character `\n` is converted into `\\n` because LTSV format does not allow to break lines
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
irb> logger.info("foo\nbar")
|
53
53
|
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo\\nbar
|
54
54
|
```
|
55
55
|
|
56
|
+
NOTE2: Notice that the tab character `\t` is converted into `\\t` because message might have a string as "\t<string>:<string>"
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
irb> logger.info("foo\tbar:baz")
|
60
|
+
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo\\tbar:baz
|
61
|
+
```
|
62
|
+
|
56
63
|
## Options
|
57
64
|
|
58
65
|
* time_key
|
data/lib/ltsv_log_formatter.rb
CHANGED
@@ -28,10 +28,16 @@ class LtsvLogFormatter
|
|
28
28
|
"#{@opts[:level_key]}:#{severity}\t" if @opts[:level_key]
|
29
29
|
end
|
30
30
|
|
31
|
+
LF = "\n".freeze
|
32
|
+
TAB = "\t".freeze
|
33
|
+
ESCAPED_LF = "\\n".freeze
|
34
|
+
ESCAPED_TAB = "\\t".freeze
|
35
|
+
ESCAPE_TARGET = /[#{LF}#{TAB}]/
|
36
|
+
|
31
37
|
def format_message(msg)
|
32
38
|
unless msg.is_a?(Hash)
|
33
39
|
msg = { @opts[:message_key] => msg }
|
34
40
|
end
|
35
|
-
msg.map {|k, v| "#{k}:#{v.to_s.gsub(
|
41
|
+
msg.map {|k, v| "#{k}:#{v.to_s.gsub(ESCAPE_TARGET, LF => ESCAPED_LF, TAB => ESCAPED_TAB)}" }.join(TAB)
|
36
42
|
end
|
37
43
|
end
|
data/ltsv_log_formatter.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "ltsv_log_formatter"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.2"
|
8
8
|
gem.authors = ["Naotoshi Seo"]
|
9
9
|
gem.email = ["sonots@gmail.com"]
|
10
10
|
gem.description = %q{A logger formatter to output log in LTSV format}
|
@@ -135,4 +135,20 @@ describe LtsvLogFormatter do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
138
|
+
|
139
|
+
describe 'escape LF and TAB' do
|
140
|
+
context 'with LF' do
|
141
|
+
it do
|
142
|
+
logger.info(foo: "bar\nbar")
|
143
|
+
expect(gets).to eq "time:#{now}\tlevel:INFO\tfoo:bar\\nbar\n"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'with TAB' do
|
148
|
+
it do
|
149
|
+
logger.info(foo: "bar\tbar")
|
150
|
+
expect(gets).to eq "time:#{now}\tlevel:INFO\tfoo:bar\\tbar\n"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
138
154
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltsv_log_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A logger formatter to output log in LTSV format
|
14
14
|
email:
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.
|
50
|
+
rubygems_version: 2.5.2
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
53
|
summary: A logger formatter to output log in LTSV format
|