scrolls 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scrolls/log.rb +7 -2
- data/lib/scrolls/parser.rb +8 -1
- data/lib/scrolls/syslog.rb +7 -3
- data/lib/scrolls/version.rb +1 -1
- data/scrolls.gemspec +1 -1
- data/test/test_parser.rb +14 -12
- data/test/test_scrolls.rb +6 -0
- metadata +4 -4
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99c754c2a68b431572505ef7952e6be9c75fcd75
|
4
|
+
data.tar.gz: 36c1c30b50e7782370bb52ae8dda662776e3788c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b0754716f62af7b741473ad61167c8f9517f5c71e6b5a2968a2e2dfa3cca5cdd399d855ba1e993c35fe423458cc7d883293ea6b67c0b0647b995fb1660710d
|
7
|
+
data.tar.gz: 5320c43a79599e2e0c48de9e2c465a12b43f61bbfb57552205a36e6a3959382735a31322d3b2b69e8682df3f81a4f1e8196ec1162697252f60210962ee9ed398
|
data/lib/scrolls/log.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "scrolls/parser"
|
2
2
|
require "scrolls/utils"
|
3
3
|
require "scrolls/syslog"
|
4
|
-
require "time"
|
5
4
|
|
6
5
|
module Scrolls
|
7
6
|
|
@@ -48,6 +47,9 @@ module Scrolls
|
|
48
47
|
|
49
48
|
def facility=(f)
|
50
49
|
@facility = LOG_FACILITY_MAP[f] if f
|
50
|
+
if Scrolls::SyslogLogger.opened?
|
51
|
+
Scrolls::SyslogLogger.new(progname, facility)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def facility
|
@@ -57,7 +59,6 @@ module Scrolls
|
|
57
59
|
def stream=(out=nil)
|
58
60
|
@defined = out.nil? ? false : true
|
59
61
|
if out == 'syslog'
|
60
|
-
progname = File.basename($0)
|
61
62
|
@stream = Scrolls::SyslogLogger.new(progname, facility)
|
62
63
|
else
|
63
64
|
@stream = sync_stream(out)
|
@@ -225,6 +226,10 @@ module Scrolls
|
|
225
226
|
end
|
226
227
|
end
|
227
228
|
|
229
|
+
def progname
|
230
|
+
File.basename($0)
|
231
|
+
end
|
232
|
+
|
228
233
|
def default_log_facility
|
229
234
|
LOG_FACILITY
|
230
235
|
end
|
data/lib/scrolls/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
module Scrolls
|
2
4
|
module Parser
|
3
5
|
extend self
|
@@ -13,7 +15,7 @@ module Scrolls
|
|
13
15
|
elsif v.nil?
|
14
16
|
"#{k}=nil"
|
15
17
|
elsif v.is_a?(Time)
|
16
|
-
"#{k}=#{v.
|
18
|
+
"#{k}=#{v.iso8601}"
|
17
19
|
else
|
18
20
|
v = v.to_s
|
19
21
|
has_single_quote = v.index("'")
|
@@ -58,6 +60,11 @@ module Scrolls
|
|
58
60
|
v = false
|
59
61
|
elsif v == "true"
|
60
62
|
v = true
|
63
|
+
else
|
64
|
+
begin
|
65
|
+
v = Time.iso8601(v)
|
66
|
+
rescue ArgumentError
|
67
|
+
end
|
61
68
|
end
|
62
69
|
|
63
70
|
vals[match[0]] = v
|
data/lib/scrolls/syslog.rb
CHANGED
@@ -28,15 +28,19 @@ module Scrolls
|
|
28
28
|
class SyslogLogger
|
29
29
|
def initialize(ident = 'scrolls', facility = Syslog::LOG_USER)
|
30
30
|
options = Syslog::LOG_PID|Syslog::LOG_CONS
|
31
|
-
|
32
|
-
@syslog = Syslog.open(ident, options, facility)
|
33
|
-
rescue RuntimeError
|
31
|
+
if Syslog.opened?
|
34
32
|
@syslog = Syslog.reopen(ident, options, facility)
|
33
|
+
else
|
34
|
+
@syslog = Syslog.open(ident, options, facility)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def puts(data)
|
39
39
|
@syslog.log(Syslog::LOG_INFO, "%s", data)
|
40
40
|
end
|
41
|
+
|
42
|
+
def self.opened?
|
43
|
+
Syslog.opened?
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
data/lib/scrolls/version.rb
CHANGED
data/scrolls.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = %q{Logging, easier, more consistent.}
|
8
8
|
gem.summary = %q{When do we log? All the time.}
|
9
9
|
gem.homepage = "https://github.com/asenchi/scrolls"
|
10
|
-
|
10
|
+
gem.license = 'MIT'
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/test/test_parser.rb
CHANGED
@@ -47,25 +47,27 @@ class TestScrollsParser < Test::Unit::TestCase
|
|
47
47
|
assert_equal data.inspect, parse(unparse(data)).inspect
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def test_unparse_constants
|
51
51
|
data = { s1: :symbol, s2: Scrolls }
|
52
52
|
assert_equal "s1=symbol s2=Scrolls", unparse(data)
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
assert_equal "t=#{Time.at(v).strftime("%FT%H:%M:%S%z")}", unparse(data)
|
55
|
+
def test_unparse_nil
|
56
|
+
data = { n: nil }
|
57
|
+
assert_equal "n=nil", unparse(data)
|
59
58
|
end
|
60
59
|
|
61
|
-
def
|
62
|
-
|
63
|
-
data = { t:
|
64
|
-
assert_equal "t
|
60
|
+
def test_unparse_time
|
61
|
+
time = Time.new(2012, 06, 19, 16, 02, 35, "+01:00")
|
62
|
+
data = { t: time }
|
63
|
+
assert_equal "t=2012-06-19T16:02:35+01:00", unparse(data)
|
65
64
|
end
|
66
65
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
66
|
+
def test_parse_time
|
67
|
+
time = Time.new(2012, 06, 19, 16, 02, 35, "+01:00")
|
68
|
+
string = "t=2012-06-19T16:02:35+01:00"
|
69
|
+
data = parse(string)
|
70
|
+
assert_equal time, data[:t]
|
70
71
|
end
|
72
|
+
|
71
73
|
end
|
data/test/test_scrolls.rb
CHANGED
@@ -148,6 +148,12 @@ class TestScrolls < Test::Unit::TestCase
|
|
148
148
|
assert_equal Syslog::LOG_LOCAL7, Scrolls.facility
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_setting_syslog_facility_after_instantiation
|
152
|
+
Scrolls.stream = 'syslog'
|
153
|
+
Scrolls.facility = 'local7'
|
154
|
+
assert_match /facility=184/, Scrolls.stream.inspect
|
155
|
+
end
|
156
|
+
|
151
157
|
def test_add_timestamp
|
152
158
|
Scrolls.add_timestamp = true
|
153
159
|
Scrolls.log(:test => "foo")
|
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.3.
|
4
|
+
version: 0.3.2
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Logging, easier, more consistent.
|
14
14
|
email:
|
@@ -18,7 +18,6 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
|
-
- .travis.yml
|
22
21
|
- Gemfile
|
23
22
|
- LICENSE
|
24
23
|
- README.md
|
@@ -36,7 +35,8 @@ files:
|
|
36
35
|
- test/test_parser.rb
|
37
36
|
- test/test_scrolls.rb
|
38
37
|
homepage: https://github.com/asenchi/scrolls
|
39
|
-
licenses:
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
40
|
metadata: {}
|
41
41
|
post_install_message:
|
42
42
|
rdoc_options: []
|