lograge 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lograge.rb +1 -0
- data/lib/lograge/formatters/ltsv.rb +43 -0
- data/lib/lograge/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0ffc5818b2ecfea5d750c2d0e82ffbfca2114dd
|
4
|
+
data.tar.gz: 18937487f75539149f07e6f35eadb31b8e8485d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba756dfa89f7112bf6677b1c5be3b495a629e8fec32a10f52c07aec06637c15e63df55d30d33dfc27db3113c9043ddd91c2aa15cc8b26bc439a57b7844b1ef53
|
7
|
+
data.tar.gz: 2fec943a32467da1728ae77aba093e8e6d8a9fde4b4b7bd3a6b6a07dbe5acc28b7234b4914b43ed486449a81770218666c42ba24107c5325a6e682cc5a76ae9e
|
data/lib/lograge.rb
CHANGED
@@ -6,6 +6,7 @@ require 'lograge/formatters/key_value'
|
|
6
6
|
require 'lograge/formatters/l2met'
|
7
7
|
require 'lograge/formatters/lines'
|
8
8
|
require 'lograge/formatters/logstash'
|
9
|
+
require 'lograge/formatters/ltsv'
|
9
10
|
require 'lograge/formatters/raw'
|
10
11
|
require 'lograge/log_subscriber'
|
11
12
|
require 'active_support/core_ext/module/attribute_accessors'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Lograge
|
2
|
+
module Formatters
|
3
|
+
class LTSV
|
4
|
+
def call(data)
|
5
|
+
fields = fields_to_display(data)
|
6
|
+
|
7
|
+
event = fields.map { |key| format(key, data[key]) }
|
8
|
+
event.join('\t')
|
9
|
+
end
|
10
|
+
|
11
|
+
def fields_to_display(data)
|
12
|
+
data.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def format(key, value)
|
16
|
+
if key == :error
|
17
|
+
# Exactly preserve the previous output
|
18
|
+
# Parsing this can be ambigious if the error messages contains
|
19
|
+
# a single quote
|
20
|
+
value = "'#{escape value}'"
|
21
|
+
else
|
22
|
+
# Ensure that we always have exactly two decimals
|
23
|
+
value = Kernel.format('%.2f', value) if value.is_a? Float
|
24
|
+
end
|
25
|
+
|
26
|
+
"#{key}:#{value}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def escape(string)
|
32
|
+
value = string.is_a?(String) ? string.dup : string.to_s
|
33
|
+
|
34
|
+
value.gsub!('\\', '\\\\')
|
35
|
+
value.gsub!('\n', '\\n')
|
36
|
+
value.gsub!('\r', '\\r')
|
37
|
+
value.gsub!('\t', '\\t')
|
38
|
+
|
39
|
+
value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/lograge/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lograge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/lograge/formatters/l2met.rb
|
98
98
|
- lib/lograge/formatters/lines.rb
|
99
99
|
- lib/lograge/formatters/logstash.rb
|
100
|
+
- lib/lograge/formatters/ltsv.rb
|
100
101
|
- lib/lograge/formatters/raw.rb
|
101
102
|
- lib/lograge/log_subscriber.rb
|
102
103
|
- lib/lograge/rails_ext/rack/logger.rb
|