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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef35d7cda907156c55fc36b1486539ac755beb03fc91fd686e396f06609dc9f3
4
- data.tar.gz: aa19774eeb977616f7e5e64b713bd612c870357ed640134c9dc9ad50d33e7c46
3
+ metadata.gz: d70168aa379a644e25091bce26f7ce86e3ffb9d6564a97246d3e6251fbe353ad
4
+ data.tar.gz: 813b7fc23789ea3436e4f18f1be99f601ec034fbf737e70bfbf8705948676aed
5
5
  SHA512:
6
- metadata.gz: fab8615f38a24e2767bb2f4b1d291f744130af82ee3326109e2c74b8d769d525cfeb761c021f4dc5c95e7fbf859a9bb5db21b29a90c11b948107e11bfc935245
7
- data.tar.gz: 37b338406b11a641ec6afb8ae28384d0460d3bf3970dd9c083cdc8eaa999d4bd4cf7b5c0dd2929719bda7751ea03cb2f7771dc06fe8911a306a0c74bedc355f0
6
+ metadata.gz: a419f6a9473eeaa2f7957db5d30ee5d1977149861542a7e28feb7e126f7413ee6a9876ff76e30414620fcf8a43eaa0abafe79408b23db0c4415a06f048ad5653
7
+ data.tar.gz: 3be6e7a630e21b35be17bf59ac480a40f2b98eec106c27dacfc245765574e317c680b5587a55064e5883b420c272ca1cdab687ac2052316fdbf53efdde7f9e45
data/README.md CHANGED
@@ -67,6 +67,7 @@ exceptions: "single"
67
67
  global_context: {}
68
68
  syslog_options: Syslog::LOG_PID|Syslog::LOG_CONS
69
69
  escape_keys: false
70
+ strict_logfmt: false
70
71
  ```
71
72
 
72
73
  ## Older Versions
@@ -37,14 +37,15 @@ module Scrolls
37
37
  attr_accessor :exceptions, :timestamp
38
38
 
39
39
  def initialize(options={})
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)
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
@@ -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('\\', '\\\\\\') + "'"
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.3"
3
3
  end
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.1
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-06-06 00:00:00.000000000 Z
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.0.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.