Skip to content

Commit

Permalink
basic logger for integrity [integrity#20]
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Nov 18, 2008
1 parent 8c84723 commit 66ed544
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/integrity.rb
Expand Up @@ -10,6 +10,7 @@
require 'dm-aggregates'

require 'yaml'
require 'logger'
require 'digest/sha1'

require "core_ext/object"
Expand All @@ -28,8 +29,9 @@ def self.root
end

def self.default_configuration
@defaults ||= { :database_uri => 'sqlite3::memory:',
@defaults ||= { :database_uri => 'sqlite3::memory:',
:export_directory => root / 'exports',
:log => STDOUT,
:base_uri => 'http://localhost:8910',
:use_basic_auth => false }
end
Expand All @@ -41,4 +43,12 @@ def self.config
def self.config=(file)
@config = default_configuration.merge(YAML.load_file(file))
end

def self.logger
@logger ||= Logger.new(config[:log])
end

def self.logger=(file)
@logger = Logger.new(file)
end
end
19 changes: 19 additions & 0 deletions spec/integrity_spec.rb
Expand Up @@ -8,6 +8,7 @@
specify 'default configuration' do
Integrity.default_configuration.should == { :database_uri => 'sqlite3::memory:',
:export_directory => Integrity.root / 'exports',
:log => STDOUT,
:base_uri => 'http://localhost:8910',
:use_basic_auth => false
}
Expand Down Expand Up @@ -46,4 +47,22 @@
end
end
end

describe "Logging" do
before(:each) { Integrity.instance_variable_set(:@logger, nil) }

it "should use Logger" do
Integrity.logger.should be_an_instance_of(Logger)
end

it "should log to STDOUT by default" do
Logger.should_receive(:new).with(STDOUT)
Integrity.logger
end

specify "Setting the log file create a new Logger logging to given file" do
Logger.should_receive(:new).with("/var/log/integrity.log")
Integrity.logger = "/var/log/integrity.log"
end
end
end

0 comments on commit 66ed544

Please sign in to comment.