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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c8d03494ac14a1c9e62cc5fb1603230062b4b7c
4
- data.tar.gz: f55c3919d123172659203c03f6ae319b681def88
3
+ metadata.gz: d8a45e22efcf405c0ad873aa6a4b5552f740f806
4
+ data.tar.gz: 2306f64eaaf2390ea2df0c356fc6ef414c770ebf
5
5
  SHA512:
6
- metadata.gz: 0628d7e8017ff0df5aa567a4dcfd2949f7c1cd606d1a30a24a731c10992c555af96f34fa0c606ac18f4c5192d4d38069166f414c1fca55c58c6d4cc959ecd72e
7
- data.tar.gz: 1e1878a898a1bfc674a996a3368e6400cc96fe295c025db101cc9f04296e71c9736b651a59f246cc280f112cc800487fd0b613b83219f06483361bcf60fd3f7b
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
@@ -27,15 +27,16 @@ module Scrolls
27
27
 
28
28
  class SyslogLogger
29
29
  def initialize(ident = 'scrolls', facility = Syslog::LOG_USER)
30
- @syslog = Syslog.open(ident, Syslog::LOG_PID|Syslog::LOG_CONS, facility)
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
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
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.stream.close if Scrolls.stream.respond_to?(:close)
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.2.9
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-12 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Logging, easier, more consistent.
14
14
  email: