scrolls 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/scrolls/logger.rb +14 -9
- data/lib/scrolls/parser.rb +2 -2
- data/lib/scrolls/version.rb +1 -1
- data/lib/scrolls.rb +1 -0
- data/test/test_parser.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70168aa379a644e25091bce26f7ce86e3ffb9d6564a97246d3e6251fbe353ad
|
4
|
+
data.tar.gz: 813b7fc23789ea3436e4f18f1be99f601ec034fbf737e70bfbf8705948676aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a419f6a9473eeaa2f7957db5d30ee5d1977149861542a7e28feb7e126f7413ee6a9876ff76e30414620fcf8a43eaa0abafe79408b23db0c4415a06f048ad5653
|
7
|
+
data.tar.gz: 3be6e7a630e21b35be17bf59ac480a40f2b98eec106c27dacfc245765574e317c680b5587a55064e5883b420c272ca1cdab687ac2052316fdbf53efdde7f9e45
|
data/README.md
CHANGED
data/lib/scrolls/logger.rb
CHANGED
@@ -37,14 +37,15 @@ module Scrolls
|
|
37
37
|
attr_accessor :exceptions, :timestamp
|
38
38
|
|
39
39
|
def initialize(options={})
|
40
|
-
@stream
|
41
|
-
@log_facility
|
42
|
-
@time_unit
|
43
|
-
@timestamp
|
44
|
-
@exceptions
|
45
|
-
@global_ctx
|
46
|
-
@syslog_opts
|
47
|
-
@escape_keys
|
40
|
+
@stream = options.fetch(:stream, STDOUT)
|
41
|
+
@log_facility = options.fetch(:facility, LOG_FACILITY)
|
42
|
+
@time_unit = options.fetch(:time_unit, "seconds")
|
43
|
+
@timestamp = options.fetch(:timestamp, false)
|
44
|
+
@exceptions = options.fetch(:exceptions, "single")
|
45
|
+
@global_ctx = options.fetch(:global_context, {})
|
46
|
+
@syslog_opts = options.fetch(:syslog_options, SYSLOG_OPTIONS)
|
47
|
+
@escape_keys = options.fetch(:escape_keys, false)
|
48
|
+
@strict_logfmt = options.fetch(:strict_logfmt, false)
|
48
49
|
|
49
50
|
# Our main entry point to ensure our options are setup properly
|
50
51
|
setup!
|
@@ -78,6 +79,10 @@ module Scrolls
|
|
78
79
|
@escape_keys
|
79
80
|
end
|
80
81
|
|
82
|
+
def strict_logfmt?
|
83
|
+
@strict_logfmt
|
84
|
+
end
|
85
|
+
|
81
86
|
def syslog_options
|
82
87
|
@syslog_opts
|
83
88
|
end
|
@@ -309,7 +314,7 @@ module Scrolls
|
|
309
314
|
|
310
315
|
def write(data)
|
311
316
|
if log_level_ok?(data[:level])
|
312
|
-
msg = Scrolls::Parser.unparse(data, escape_keys=escape_keys?)
|
317
|
+
msg = Scrolls::Parser.unparse(data, escape_keys=escape_keys?, strict_logfmt=strict_logfmt?)
|
313
318
|
@logger.log(msg)
|
314
319
|
end
|
315
320
|
end
|
data/lib/scrolls/parser.rb
CHANGED
@@ -4,7 +4,7 @@ module Scrolls
|
|
4
4
|
module Parser
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def unparse(data, escape_keys=false)
|
7
|
+
def unparse(data, escape_keys=false, strict_logfmt=false)
|
8
8
|
data.map do |(k,v)|
|
9
9
|
k = Scrolls::Utils.escape_chars(k) if escape_keys
|
10
10
|
|
@@ -23,7 +23,7 @@ module Scrolls
|
|
23
23
|
has_single_quote = v.index("'")
|
24
24
|
has_double_quote = v.index('"')
|
25
25
|
if v =~ /[ =:,]/
|
26
|
-
if has_single_quote && has_double_quote
|
26
|
+
if (has_single_quote || strict_logfmt) && has_double_quote
|
27
27
|
v = '"' + v.gsub(/\\|"/) { |c| "\\#{c}" } + '"'
|
28
28
|
elsif has_double_quote
|
29
29
|
v = "'" + v.gsub('\\', '\\\\\\') + "'"
|
data/lib/scrolls/version.rb
CHANGED
data/lib/scrolls.rb
CHANGED
@@ -15,6 +15,7 @@ module Scrolls
|
|
15
15
|
# global_context - Immutable context to prepend all messages with
|
16
16
|
# syslog_options - Syslog options (default: Syslog::LOG_PID|Syslog::LOG_CONS)
|
17
17
|
# escape_keys - Escape chars in keys
|
18
|
+
# strict_logfmt - Always use double quotes to quote values
|
18
19
|
#
|
19
20
|
def init(options={})
|
20
21
|
# Set a hint whether #init was called.
|
data/test/test_parser.rb
CHANGED
@@ -88,6 +88,12 @@ class TestScrollsParser < Minitest::Test
|
|
88
88
|
unparse(data, escape_keys=true)
|
89
89
|
end
|
90
90
|
|
91
|
+
def test_unparse_strict_logfmt
|
92
|
+
data = { s: 'echo "hello"' }
|
93
|
+
assert_equal 's="echo \"hello\""', unparse(data, escape_keys=false, strict_logfmt=true)
|
94
|
+
assert_equal data.inspect, parse(unparse(data, escape_keys=false, strict_logfmt=true)).inspect
|
95
|
+
end
|
96
|
+
|
91
97
|
def test_parse_time
|
92
98
|
time = Time.new(2012, 06, 19, 16, 02, 35, "+01:00")
|
93
99
|
string = "t=2012-06-19T16:02:35+01:00"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrolls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Curt Micol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Logging, easier, more consistent.
|
14
14
|
email:
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.2.29
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: When do we log? All the time.
|