steno 0.0.3 → 0.0.5

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.
data/lib/steno/config.rb CHANGED
@@ -10,12 +10,25 @@ end
10
10
 
11
11
  class Steno::Config
12
12
  class << self
13
+ # Creates a config given a yaml file of the following form:
14
+ #
15
+ # logging:
16
+ # level: <info, debug, etc>
17
+ # file: </path/to/logfile>
18
+ # syslog: <syslog name>
19
+ #
20
+ # @param [String] path Path to yaml config
21
+ # @param [Hash] overrides
22
+ #
23
+ # @return [Steno::Config]
13
24
  def from_file(path, overrides = {})
14
25
  h = YAML.load_file(path)
15
26
 
27
+ h = h["logging"] || {}
28
+
16
29
  opts = {
17
30
  :sinks => [],
18
- :default_log_level => h["level"].to_sym,
31
+ :default_log_level => h["level"].nil? ? :info : h["level"].to_sym,
19
32
  }
20
33
 
21
34
  if h["file"]
data/lib/steno/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steno
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/steno.rb CHANGED
@@ -3,7 +3,6 @@ require "thread"
3
3
  require "steno/codec"
4
4
  require "steno/config"
5
5
  require "steno/context"
6
- require "steno/core_ext"
7
6
  require "steno/errors"
8
7
  require "steno/log_level"
9
8
  require "steno/logger"
@@ -0,0 +1,80 @@
1
+ require "fileutils"
2
+ require "yaml"
3
+
4
+ require "spec_helper"
5
+
6
+ describe Steno::Config do
7
+ describe ".from_file" do
8
+ before :each do
9
+ @tmpdir = Dir.mktmpdir
10
+ @config_path = File.join(@tmpdir, "config.yml")
11
+ @log_path = File.join(@tmpdir, "test.log")
12
+ end
13
+
14
+ after :each do
15
+ FileUtils.rm_rf(@tmpdir)
16
+ end
17
+
18
+ it "should return Steno::Config instance with sane defaults" do
19
+ write_config(@config_path, {})
20
+
21
+ config = Steno::Config.from_file(@config_path)
22
+
23
+ config.sinks.size.should == 1
24
+ config.sinks[0].class.should == Steno::Sink::IO
25
+
26
+ config.default_log_level.should == :info
27
+
28
+ config.context.should.class == Steno::Context::Null
29
+
30
+ config.codec.should.class == Steno::Codec::Json
31
+ end
32
+
33
+ it "should set the default_log_level if a key with the same name is supplied" do
34
+ write_config(@config_path, { "level" => "debug2" })
35
+
36
+ Steno::Config.from_file(@config_path).default_log_level.should == :debug2
37
+ end
38
+
39
+ it "should add a file sink if the 'file' key is specified" do
40
+ write_config(@config_path, { "file" => @log_path })
41
+ mock_sink = mock("sink")
42
+ mock_sink.stub(:codec=)
43
+
44
+ Steno::Sink::IO.should_receive(:for_file).with(@log_path).and_return(mock_sink)
45
+ config = Steno::Config.from_file(@config_path)
46
+ config.sinks.size.should == 1
47
+ config.sinks[0].should == mock_sink
48
+ end
49
+
50
+ it "should add a syslog sink if the 'syslog' key is specified" do
51
+ write_config(@config_path, { "syslog" => "test" })
52
+ mock_sink = mock("sink")
53
+ mock_sink.should_receive(:open).with("test")
54
+ mock_sink.stub(:codec=)
55
+
56
+ Steno::Sink::Syslog.should_receive(:instance).twice().and_return(mock_sink)
57
+
58
+ config = Steno::Config.from_file(@config_path)
59
+ config.sinks.size.should == 1
60
+ config.sinks[0].should == mock_sink
61
+ end
62
+
63
+ it "should merge supplied overrides with the file based config" do
64
+ write_config(@config_path, { "default_log_level" => "debug" })
65
+
66
+ context = Steno::Context::ThreadLocal.new
67
+ config = Steno::Config.from_file(@config_path,
68
+ :default_log_level => "warn",
69
+ :context => context)
70
+ config.context.should == context
71
+ config.default_log_level.should == :warn
72
+ end
73
+ end
74
+
75
+ def write_config(path, config)
76
+ File.open(path, "w+") do |f|
77
+ f.write(YAML.dump({ "logging" => config }))
78
+ end
79
+ end
80
+ end
@@ -8,8 +8,13 @@ end
8
8
  describe Class do
9
9
  describe "#logger" do
10
10
  it "should request a logger named after the class" do
11
- Steno.should_receive(:logger).with("Foo::Bar")
11
+ expect do
12
+ Foo::Bar.logger
13
+ end.to raise_error(/undefined/)
14
+
15
+ require "steno/core_ext"
12
16
  x = Foo::Bar.logger
17
+ x.should_not be_nil
13
18
  end
14
19
  end
15
20
  end
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.3
4
+ version: 0.0.5
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-23 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &15618460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *15618460
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: yajl-ruby
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &15617860 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *15617860
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: ci_reporter
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &15617180 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *15617180
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: rack-test
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &15616200 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *15616200
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: rake
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &15615780 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '0'
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *15615780
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: rspec
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &15615360 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ! '>='
@@ -101,12 +76,7 @@ dependencies:
101
76
  version: '0'
102
77
  type: :development
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
79
+ version_requirements: *15615360
110
80
  description: A thread-safe logging library designed to support multiple log destinations.
111
81
  email:
112
82
  - mpage@rbcon.com
@@ -137,12 +107,13 @@ files:
137
107
  - lib/steno/sink/syslog.rb
138
108
  - lib/steno/tagged_logger.rb
139
109
  - lib/steno/version.rb
140
- - spec/core_ext_spec.rb
141
110
  - spec/spec_helper.rb
142
111
  - spec/support/barrier.rb
143
112
  - spec/support/null_sink.rb
144
113
  - spec/support/shared_context_specs.rb
114
+ - spec/unit/config_spec.rb
145
115
  - spec/unit/context_spec.rb
116
+ - spec/unit/core_ext_spec.rb
146
117
  - spec/unit/http_handler_spec.rb
147
118
  - spec/unit/io_sink_spec.rb
148
119
  - spec/unit/json_codec_spec.rb
@@ -173,17 +144,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
144
  version: '0'
174
145
  requirements: []
175
146
  rubyforge_project:
176
- rubygems_version: 1.8.23
147
+ rubygems_version: 1.8.10
177
148
  signing_key:
178
149
  specification_version: 3
179
150
  summary: A logging library.
180
151
  test_files:
181
- - spec/core_ext_spec.rb
182
152
  - spec/spec_helper.rb
183
153
  - spec/support/barrier.rb
184
154
  - spec/support/null_sink.rb
185
155
  - spec/support/shared_context_specs.rb
156
+ - spec/unit/config_spec.rb
186
157
  - spec/unit/context_spec.rb
158
+ - spec/unit/core_ext_spec.rb
187
159
  - spec/unit/http_handler_spec.rb
188
160
  - spec/unit/io_sink_spec.rb
189
161
  - spec/unit/json_codec_spec.rb