scrolls 0.2.7 → 0.2.8

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8beec4af8465e8505c319ca48c0067fcfdff5f35
4
+ data.tar.gz: 8e9ddcc0a1b856f7b78fb03f4cc3ce1c20b5dc98
5
+ SHA512:
6
+ metadata.gz: 7f06f0c33ad9191f1d3e034bb25d892aa5f3ba794c9ea622ab04531c0e86217ece67f0849dab0b52e57473a858ace2a4089189407ed67ec0535ce259263125f1
7
+ data.tar.gz: 3c2007e3912a15799b1905794f3325026d4636d7418f260c5086d109dd71872324f18aebd7bec3f96c8cea6c4fd79eb11bba1c6e284988d8b1d03f5e313b9265
data/lib/scrolls/log.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "scrolls/parser"
2
2
  require "scrolls/utils"
3
+ require "scrolls/syslog"
3
4
 
4
5
  module Scrolls
5
6
 
@@ -44,10 +45,21 @@ module Scrolls
44
45
  @global_context.update { |previous_data| previous_data.merge(new_data) }
45
46
  end
46
47
 
48
+ def facility=(f)
49
+ @facility = LOG_FACILITY_MAP[f] if f
50
+ end
51
+
52
+ def facility
53
+ @facility ||= default_log_facility
54
+ end
55
+
47
56
  def stream=(out=nil)
48
57
  @defined = out.nil? ? false : true
49
-
50
- @stream = sync_stream(out)
58
+ if out == 'syslog'
59
+ @stream = Scrolls::SyslogLogger.new($0, facility)
60
+ else
61
+ @stream = sync_stream(out)
62
+ end
51
63
  end
52
64
 
53
65
  def stream
@@ -198,5 +210,8 @@ module Scrolls
198
210
  end
199
211
  end
200
212
 
213
+ def default_log_facility
214
+ LOG_FACILITY
215
+ end
201
216
  end
202
217
  end
@@ -0,0 +1,41 @@
1
+ require 'syslog'
2
+
3
+ module Scrolls
4
+
5
+ LOG_FACILITY = ENV['LOG_FACILITY'] || Syslog::LOG_USER
6
+ LOG_FACILITY_MAP = {
7
+ "auth" => Syslog::LOG_AUTH,
8
+ "authpriv" => Syslog::LOG_AUTHPRIV,
9
+ "cron" => Syslog::LOG_CRON,
10
+ "daemon" => Syslog::LOG_DAEMON,
11
+ "ftp" => Syslog::LOG_FTP,
12
+ "kern" => Syslog::LOG_KERN,
13
+ "mail" => Syslog::LOG_MAIL,
14
+ "news" => Syslog::LOG_NEWS,
15
+ "syslog" => Syslog::LOG_SYSLOG,
16
+ "user" => Syslog::LOG_USER,
17
+ "uucp" => Syslog::LOG_UUCP,
18
+ "local0" => Syslog::LOG_LOCAL0,
19
+ "local1" => Syslog::LOG_LOCAL1,
20
+ "local2" => Syslog::LOG_LOCAL2,
21
+ "local3" => Syslog::LOG_LOCAL3,
22
+ "local4" => Syslog::LOG_LOCAL4,
23
+ "local5" => Syslog::LOG_LOCAL5,
24
+ "local6" => Syslog::LOG_LOCAL6,
25
+ "local7" => Syslog::LOG_LOCAL7,
26
+ }
27
+
28
+ class SyslogLogger
29
+ def initialize(ident = 'scrolls', facility = Syslog::LOG_USER)
30
+ @syslog = Syslog.open(ident, Syslog::LOG_PID|Syslog::LOG_CONS, facility)
31
+ end
32
+
33
+ def puts(data)
34
+ @syslog.log(Syslog::LOG_INFO, data)
35
+ end
36
+
37
+ def close
38
+ @syslog.close
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
data/lib/scrolls.rb CHANGED
@@ -28,7 +28,7 @@ module Scrolls
28
28
  Log.global_context
29
29
  end
30
30
  end
31
-
31
+
32
32
  def add_global_context(data)
33
33
  Log.add_global_context(data)
34
34
  end
@@ -73,10 +73,37 @@ module Scrolls
73
73
  Log.log_exception(data, e)
74
74
  end
75
75
 
76
+ # Public: Setup a logging facility (default: Syslog::LOG_USER)
77
+ #
78
+ # facility - Syslog facility
79
+ #
80
+ # Examples
81
+ #
82
+ # Scrolls.facility = Syslog::LOG_LOCAL7
83
+ #
84
+ def facility=(f)
85
+ Log.facility=(f)
86
+ end
87
+
88
+ # Public: Return the Syslog facility
89
+ #
90
+ # Examples
91
+ #
92
+ # Scrolls.facility
93
+ # => 8
94
+ #
95
+ def facility
96
+ Log.facility
97
+ end
98
+
76
99
  # Public: Setup a new output (default: STDOUT)
77
100
  #
78
101
  # out - New output
79
102
  #
103
+ # Options
104
+ #
105
+ # syslog - Load 'Scrolls::SyslogLogger'
106
+ #
80
107
  # Examples
81
108
  #
82
109
  # Scrolls.stream = StringIO.new
data/test/test_scrolls.rb CHANGED
@@ -8,47 +8,50 @@ class TestScrolls < Test::Unit::TestCase
8
8
 
9
9
  def teardown
10
10
  Scrolls.global_context({})
11
+ # Reset our syslog context
12
+ Scrolls.facility = Scrolls::LOG_FACILITY
13
+ Scrolls.stream.close if Scrolls.stream.respond_to?(:close)
11
14
  end
12
15
 
13
- def test_construct
14
- assert_equal StringIO, Scrolls.stream.class
15
- end
16
+ # def test_construct
17
+ # assert_equal StringIO, Scrolls.stream.class
18
+ # end
16
19
 
17
20
  def test_default_global_context
18
21
  assert_equal Hash.new, Scrolls.global_context
19
22
  end
20
23
 
21
24
  def test_setting_global_context
22
- Scrolls.global_context(g: "g")
23
- Scrolls.log(d: "d")
25
+ Scrolls.global_context(:g => "g")
26
+ Scrolls.log(:d => "d")
24
27
  assert_equal "g=g d=d\n", @out.string
25
28
  end
26
29
 
27
30
  def test_adding_to_global_context
28
- Scrolls.global_context(g: "g")
29
- Scrolls.add_global_context(h: "h")
30
- Scrolls.log(d: "d")
31
+ Scrolls.global_context(:g => "g")
32
+ Scrolls.add_global_context(:h => "h")
33
+ Scrolls.log(:d => "d")
31
34
  assert_equal "g=g h=h d=d\n", @out.string
32
35
  end
33
36
 
34
37
  def test_default_context
35
- Scrolls.log(data: "d")
38
+ Scrolls.log(:data => "d")
36
39
  assert_equal Hash.new, Scrolls::Log.context
37
40
  end
38
41
 
39
42
  def test_setting_context
40
- Scrolls.context(c: "c") { Scrolls.log(i: "i") }
43
+ Scrolls.context(:c =>"c") { Scrolls.log(:i => "i") }
41
44
  output = "c=c i=i\n"
42
45
  assert_equal output, @out.string
43
46
  end
44
47
 
45
48
  def test_all_the_contexts
46
- Scrolls.global_context(g: "g")
47
- Scrolls.log(o: "o") do
48
- Scrolls.context(c: "c") do
49
- Scrolls.log(ic: "i")
49
+ Scrolls.global_context(:g => "g")
50
+ Scrolls.log(:o => "o") do
51
+ Scrolls.context(:c => "c") do
52
+ Scrolls.log(:ic => "i")
50
53
  end
51
- Scrolls.log(i: "i")
54
+ Scrolls.log(:i => "i")
52
55
  end
53
56
  @out.truncate(37)
54
57
  output = "g=g o=o at=start\ng=g c=c ic=i\ng=g i=i"
@@ -56,11 +59,11 @@ class TestScrolls < Test::Unit::TestCase
56
59
  end
57
60
 
58
61
  def test_deeply_nested_context
59
- Scrolls.log(o: "o") do
60
- Scrolls.context(c: "c") do
61
- Scrolls.log(ic: "i")
62
+ Scrolls.log(:o => "o") do
63
+ Scrolls.context(:c => "c") do
64
+ Scrolls.log(:ic => "i")
62
65
  end
63
- Scrolls.log(i: "i")
66
+ Scrolls.log(:i => "i")
64
67
  end
65
68
  @out.truncate(21)
66
69
  output = "o=o at=start\nc=c ic=i"
@@ -68,11 +71,11 @@ class TestScrolls < Test::Unit::TestCase
68
71
  end
69
72
 
70
73
  def test_deeply_nested_context_dropped
71
- Scrolls.log(o: "o") do
72
- Scrolls.context(c: "c") do
73
- Scrolls.log(ic: "i")
74
+ Scrolls.log(:o => "o") do
75
+ Scrolls.context(:c => "c") do
76
+ Scrolls.log(:ic => "i")
74
77
  end
75
- Scrolls.log(i: "i")
78
+ Scrolls.log(:i => "i")
76
79
  end
77
80
  @out.truncate(25)
78
81
  output = "o=o at=start\nc=c ic=i\ni=i"
@@ -81,12 +84,12 @@ class TestScrolls < Test::Unit::TestCase
81
84
 
82
85
  def test_context_after_exception
83
86
  begin
84
- Scrolls.context(c: 'c') do
87
+ Scrolls.context(:c => 'c') do
85
88
  raise "Error from inside of context"
86
89
  end
87
90
  fail "Exception did not escape context block"
88
91
  rescue => e
89
- Scrolls.log(o: 'o')
92
+ Scrolls.log(:o => 'o')
90
93
  assert_equal "o=o\n", @out.string
91
94
  end
92
95
  end
@@ -107,12 +110,12 @@ class TestScrolls < Test::Unit::TestCase
107
110
  end
108
111
 
109
112
  def test_logging
110
- Scrolls.log(test: "basic")
113
+ Scrolls.log(:test => "basic")
111
114
  assert_equal "test=basic\n", @out.string
112
115
  end
113
116
 
114
117
  def test_logging_block
115
- Scrolls.log(outer: "o") { Scrolls.log(inner: "i") }
118
+ Scrolls.log(:outer => "o") { Scrolls.log(:inner => "i") }
116
119
  output = "outer=o at=start\ninner=i\nouter=o at=finish elapsed=0.000\n"
117
120
  assert_equal output, @out.string
118
121
  end
@@ -121,7 +124,7 @@ class TestScrolls < Test::Unit::TestCase
121
124
  begin
122
125
  raise Exception
123
126
  rescue Exception => e
124
- Scrolls.log_exception({test: "exception"}, e)
127
+ Scrolls.log_exception({:test => "exception"}, e)
125
128
  end
126
129
 
127
130
  oneline_backtrace = @out.string.gsub("\n", 'XX')
@@ -129,4 +132,19 @@ class TestScrolls < Test::Unit::TestCase
129
132
  assert_match /test=exception at=exception.*test_log_exception.*XX.*minitest/,
130
133
  oneline_backtrace
131
134
  end
135
+
136
+ def test_syslog_integration
137
+ Scrolls.stream = 'syslog'
138
+ assert_equal Scrolls::SyslogLogger, Scrolls.stream.class
139
+ end
140
+
141
+ def test_syslog_facility
142
+ Scrolls.stream = 'syslog'
143
+ assert_equal Syslog::LOG_USER, Scrolls.facility
144
+ end
145
+
146
+ def test_setting_syslog_facility
147
+ Scrolls.facility = "local7"
148
+ assert_equal Syslog::LOG_LOCAL7, Scrolls.facility
149
+ end
132
150
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrolls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
5
- prerelease:
4
+ version: 0.2.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Curt Micol
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-10 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Logging, easier, more consistent.
15
14
  email:
@@ -28,6 +27,7 @@ files:
28
27
  - lib/scrolls/atomic.rb
29
28
  - lib/scrolls/log.rb
30
29
  - lib/scrolls/parser.rb
30
+ - lib/scrolls/syslog.rb
31
31
  - lib/scrolls/utils.rb
32
32
  - lib/scrolls/version.rb
33
33
  - scrolls.gemspec
@@ -37,27 +37,26 @@ files:
37
37
  - test/test_scrolls.rb
38
38
  homepage: https://github.com/asenchi/scrolls
39
39
  licenses: []
40
+ metadata: {}
40
41
  post_install_message:
41
42
  rdoc_options: []
42
43
  require_paths:
43
44
  - lib
44
45
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
46
  requirements:
47
- - - ! '>='
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
51
  requirements:
53
- - - ! '>='
52
+ - - '>='
54
53
  - !ruby/object:Gem::Version
55
54
  version: '0'
56
55
  requirements: []
57
56
  rubyforge_project:
58
- rubygems_version: 1.8.23
57
+ rubygems_version: 2.0.3
59
58
  signing_key:
60
- specification_version: 3
59
+ specification_version: 4
61
60
  summary: When do we log? All the time.
62
61
  test_files:
63
62
  - test/test_atomic.rb