scrolls 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/scrolls/log.rb +14 -0
- data/lib/scrolls/syslog.rb +7 -6
- data/lib/scrolls/version.rb +1 -1
- data/lib/scrolls.rb +24 -0
- data/test/test_scrolls.rb +8 -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: d8a45e22efcf405c0ad873aa6a4b5552f740f806
|
4
|
+
data.tar.gz: 2306f64eaaf2390ea2df0c356fc6ef414c770ebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd0aee8262fae69f7f57a09e79aad31613bdc5224450e55c347e3eeba6e8a59bd5f784be035827bb043818f01e8f680bddd04a3f0c1b4b69b7c909fdffebe90
|
7
|
+
data.tar.gz: 37497139c5d177d53fa929225c37f5bc851921fe13e143c83a8af9c0bbcdcac405e6fec059bbdaa8017f30e095f3cf3fc2a673e12b3f44f1317fb11b8de3af2c
|
data/lib/scrolls/log.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "scrolls/parser"
|
2
2
|
require "scrolls/utils"
|
3
3
|
require "scrolls/syslog"
|
4
|
+
require "time"
|
4
5
|
|
5
6
|
module Scrolls
|
6
7
|
|
@@ -75,12 +76,25 @@ module Scrolls
|
|
75
76
|
@tunit ||= default_time_unit
|
76
77
|
end
|
77
78
|
|
79
|
+
def add_timestamp=(b)
|
80
|
+
@add_timestamp = !!b
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_timestamp
|
84
|
+
@add_timestamp || false
|
85
|
+
end
|
86
|
+
|
78
87
|
def log(data, &blk)
|
79
88
|
if gc = get_global_context
|
80
89
|
ctx = gc.merge(context)
|
81
90
|
logdata = ctx.merge(data)
|
82
91
|
end
|
83
92
|
|
93
|
+
# By merging the logdata into the timestamp, rather than vice-versa, we
|
94
|
+
# ensure that the timestamp comes first in the Hash, and is placed first
|
95
|
+
# on the output, which helps with readability.
|
96
|
+
logdata = { :now => Time.now }.merge(logdata) if add_timestamp
|
97
|
+
|
84
98
|
unless blk
|
85
99
|
write(logdata)
|
86
100
|
else
|
data/lib/scrolls/syslog.rb
CHANGED
@@ -27,15 +27,16 @@ module Scrolls
|
|
27
27
|
|
28
28
|
class SyslogLogger
|
29
29
|
def initialize(ident = 'scrolls', facility = Syslog::LOG_USER)
|
30
|
-
|
30
|
+
options = Syslog::LOG_PID|Syslog::LOG_CONS
|
31
|
+
begin
|
32
|
+
@syslog = Syslog.open(ident, options, facility)
|
33
|
+
rescue RuntimeError
|
34
|
+
@syslog = Syslog.reopen(ident, options, facility)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
def puts(data)
|
34
|
-
@syslog.log(Syslog::LOG_INFO, data)
|
35
|
-
end
|
36
|
-
|
37
|
-
def close
|
38
|
-
@syslog.close
|
39
|
+
@syslog.log(Syslog::LOG_INFO, data, nil)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/scrolls/version.rb
CHANGED
data/lib/scrolls.rb
CHANGED
@@ -145,4 +145,28 @@ module Scrolls
|
|
145
145
|
def time_unit
|
146
146
|
Log.time_unit
|
147
147
|
end
|
148
|
+
|
149
|
+
# Public: Set whether to include a timestamp (now=<ISO8601>) field in the log
|
150
|
+
# output (default: false)
|
151
|
+
#
|
152
|
+
# Examples
|
153
|
+
#
|
154
|
+
# Scrolls.add_timestamp = true
|
155
|
+
#
|
156
|
+
def add_timestamp=(boolean)
|
157
|
+
Log.add_timestamp = boolean
|
158
|
+
end
|
159
|
+
|
160
|
+
# Public: Return whether the timestamp field will be included in the log
|
161
|
+
# output.
|
162
|
+
#
|
163
|
+
# Examples
|
164
|
+
#
|
165
|
+
# Scrolls.add_timestamp
|
166
|
+
# => true
|
167
|
+
#
|
168
|
+
def add_timestamp
|
169
|
+
Log.add_timestamp
|
170
|
+
end
|
171
|
+
|
148
172
|
end
|
data/test/test_scrolls.rb
CHANGED
@@ -10,7 +10,7 @@ class TestScrolls < Test::Unit::TestCase
|
|
10
10
|
Scrolls.global_context({})
|
11
11
|
# Reset our syslog context
|
12
12
|
Scrolls.facility = Scrolls::LOG_FACILITY
|
13
|
-
Scrolls.
|
13
|
+
Scrolls.add_timestamp = false
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_construct
|
@@ -147,4 +147,11 @@ class TestScrolls < Test::Unit::TestCase
|
|
147
147
|
Scrolls.facility = "local7"
|
148
148
|
assert_equal Syslog::LOG_LOCAL7, Scrolls.facility
|
149
149
|
end
|
150
|
+
|
151
|
+
def test_add_timestamp
|
152
|
+
Scrolls.add_timestamp = true
|
153
|
+
Scrolls.log(:test => "foo")
|
154
|
+
iso8601_regexp = "(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?"
|
155
|
+
assert_match(/^now=#{iso8601_regexp} test=foo$/, @out.string)
|
156
|
+
end
|
150
157
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Curt Micol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Logging, easier, more consistent.
|
14
14
|
email:
|