steno 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/steno/config.rb +32 -9
- data/lib/steno/version.rb +1 -1
- data/spec/unit/config_spec.rb +53 -0
- metadata +45 -15
data/lib/steno/config.rb
CHANGED
@@ -23,28 +23,49 @@ class Steno::Config
|
|
23
23
|
# @return [Steno::Config]
|
24
24
|
def from_file(path, overrides = {})
|
25
25
|
h = YAML.load_file(path)
|
26
|
-
|
27
26
|
h = h["logging"] || {}
|
27
|
+
new(to_config_hash(h).merge(overrides))
|
28
|
+
end
|
29
|
+
|
30
|
+
def from_hash(hash)
|
31
|
+
new(to_config_hash(hash))
|
32
|
+
end
|
28
33
|
|
34
|
+
def to_config_hash(hash)
|
35
|
+
hash ||= {}
|
36
|
+
hash = symbolize_keys(hash)
|
37
|
+
|
38
|
+
level = hash[:level] || hash[:default_log_level]
|
29
39
|
opts = {
|
30
40
|
:sinks => [],
|
31
|
-
:default_log_level =>
|
41
|
+
:default_log_level => level.nil? ? :info : level.to_sym
|
32
42
|
}
|
33
43
|
|
34
|
-
if
|
35
|
-
opts[:sinks] << Steno::Sink::IO.for_file(
|
44
|
+
if hash[:file]
|
45
|
+
opts[:sinks] << Steno::Sink::IO.for_file(hash[:file])
|
36
46
|
end
|
37
47
|
|
38
|
-
if
|
39
|
-
Steno::Sink::Syslog.instance.open(
|
48
|
+
if hash[:syslog]
|
49
|
+
Steno::Sink::Syslog.instance.open(hash[:syslog])
|
40
50
|
opts[:sinks] << Steno::Sink::Syslog.instance
|
41
51
|
end
|
42
52
|
|
43
|
-
if opts[:sinks].empty?
|
44
|
-
|
53
|
+
opts[:sinks] << Steno::Sink::IO.new(STDOUT) if opts[:sinks].empty?
|
54
|
+
opts
|
55
|
+
end
|
56
|
+
|
57
|
+
def symbolize_keys(hash)
|
58
|
+
hash ||= {}
|
59
|
+
symbolized = {}
|
60
|
+
hash.each_key do |key|
|
61
|
+
if !key.is_a? Symbol
|
62
|
+
symbolized[key.to_sym] = hash[key]
|
63
|
+
else
|
64
|
+
symbolized[key] = hash[key]
|
65
|
+
end
|
45
66
|
end
|
46
67
|
|
47
|
-
|
68
|
+
symbolized
|
48
69
|
end
|
49
70
|
end
|
50
71
|
|
@@ -66,4 +87,6 @@ class Steno::Config
|
|
66
87
|
@default_log_level = :info
|
67
88
|
end
|
68
89
|
end
|
90
|
+
|
91
|
+
private_class_method :symbolize_keys
|
69
92
|
end
|
data/lib/steno/version.rb
CHANGED
data/spec/unit/config_spec.rb
CHANGED
@@ -4,6 +4,52 @@ require "yaml"
|
|
4
4
|
require "spec_helper"
|
5
5
|
|
6
6
|
describe Steno::Config do
|
7
|
+
describe ".from_hash" do
|
8
|
+
before :each do
|
9
|
+
@log_path = "some_file"
|
10
|
+
|
11
|
+
@mock_sink_file = mock("sink")
|
12
|
+
@mock_sink_file.stub(:codec=)
|
13
|
+
Steno::Sink::IO.should_receive(:for_file).with(@log_path)
|
14
|
+
.and_return(@mock_sink_file)
|
15
|
+
|
16
|
+
@mock_sink_syslog = mock("sink")
|
17
|
+
@mock_sink_syslog.stub(:codec=)
|
18
|
+
@mock_sink_syslog.should_receive(:open).with("test")
|
19
|
+
Steno::Sink::Syslog.should_receive(:instance).twice()
|
20
|
+
.and_return(@mock_sink_syslog)
|
21
|
+
end
|
22
|
+
|
23
|
+
after :each do
|
24
|
+
@config = Steno::Config.from_hash(@hash)
|
25
|
+
|
26
|
+
@config.default_log_level.should == :debug2
|
27
|
+
@config.context.should.class == Steno::Context::Null
|
28
|
+
@config.codec.should.class == Steno::Codec::Json
|
29
|
+
|
30
|
+
@config.sinks.size.should == 2
|
31
|
+
@config.sinks.should =~ [@mock_sink_file, @mock_sink_syslog]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should work for symbolized keys" do
|
35
|
+
@hash = {
|
36
|
+
:file => @log_path,
|
37
|
+
:level => "debug2",
|
38
|
+
:default_log_level => "warn",
|
39
|
+
:syslog => "test"
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should work for non-symbolized keys" do
|
44
|
+
@hash = {
|
45
|
+
"file" => @log_path,
|
46
|
+
"level" => "debug2",
|
47
|
+
"default_log_level" => "warn",
|
48
|
+
"syslog" => "test"
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
7
53
|
describe ".from_file" do
|
8
54
|
before :each do
|
9
55
|
@tmpdir = Dir.mktmpdir
|
@@ -32,7 +78,14 @@ describe Steno::Config do
|
|
32
78
|
|
33
79
|
it "should set the default_log_level if a key with the same name is supplied" do
|
34
80
|
write_config(@config_path, { "level" => "debug2" })
|
81
|
+
Steno::Config.from_file(@config_path).default_log_level.should == :debug2
|
82
|
+
|
83
|
+
write_config(@config_path, { "default_log_level" => "debug2" })
|
84
|
+
Steno::Config.from_file(@config_path).default_log_level.should == :debug2
|
85
|
+
end
|
35
86
|
|
87
|
+
it "should read the 'level' key if both default_log_level and level are spscified" do
|
88
|
+
write_config(@config_path, { "level" => "debug2", "default_log_level" => "warn" })
|
36
89
|
Steno::Config.from_file(@config_path).default_log_level.should == :debug2
|
37
90
|
end
|
38
91
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: yajl-ruby
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: ci_reporter
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rack-test
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rake
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rspec
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
description: A thread-safe logging library designed to support multiple log destinations.
|
81
111
|
email:
|
82
112
|
- mpage@rbcon.com
|
@@ -148,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
178
|
version: '0'
|
149
179
|
requirements: []
|
150
180
|
rubyforge_project:
|
151
|
-
rubygems_version: 1.8.
|
181
|
+
rubygems_version: 1.8.23
|
152
182
|
signing_key:
|
153
183
|
specification_version: 3
|
154
184
|
summary: A logging library.
|