Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative log file creation #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/daemon_kit/abstract_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize( log_path = nil )
if log_path.to_s == "syslog"
@backend = :syslog
else
@logger_file = log_path || "#{DAEMON_ROOT}/log/#{DAEMON_ENV}.log"
@logger_file = set_logger_file(log_path)
@backend = :logger
end

Expand Down Expand Up @@ -194,6 +194,14 @@ def create_logger
end
end

def set_logger_file(log_path)
if log_path
log_path.start_with?('/') ? log_path : [DAEMON_ROOT, log_path].join('/')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it may be an issue, but since I don't write or deploy to a Windows box, I have no way of testing it. My workaround for the current version is just to pass the full absolute path. Maybe a better solution is to just change the filename, which is all I really need to do anyway.

else
"#{DAEMON_ROOT}/log/#{DAEMON_ENV}.log"
end
end

def create_standard_logger
log_path = File.dirname( @logger_file )
unless File.directory?( log_path )
Expand Down
16 changes: 15 additions & 1 deletion spec/abstract_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
@logger.level = :debug
end

context "custom log files" do
it "should set relative log files" do
@log_file = "log/spec_custom.log"
@logger = DaemonKit::AbstractLogger.new( @log_file )
expect(@logger.instance_variable_get("@logger_file")).to eq("#{DAEMON_ROOT}/log/spec_custom.log")
end

it "should set absolute log files" do
@log_file = "/var/log/spec_custom.log"
@logger = DaemonKit::AbstractLogger.new( @log_file )
expect(@logger.instance_variable_get("@logger_file")).to eq("/var/log/spec_custom.log")
end
end

it "should have a log level" do
@logger.level.should == :debug
end
Expand Down Expand Up @@ -67,7 +81,7 @@
IO.readlines( @log_file ).last.should match(/\[ANY\].*Unknown test/)
end

pending "should log the caller file and line number" do
skip "should log the caller file and line number" do
f = File.basename(__FILE__)
l = __LINE__ + 2

Expand Down
8 changes: 4 additions & 4 deletions spec/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class FooConfig

it "should support default values" do
lambda {
@foo.has_default.should be_true
}.should_not raise_error( NoMethodError )
@foo.has_default.should be_truthy
}.should_not raise_error
end

it "should support overwriting unlocked defaults" do
lambda {
@foo.has_default = false
@foo.has_default.should be_false
@foo.has_default.should be_falsey
}.should_not raise_error
end

it "should support no default values" do
lambda {
@foo.no_default.should be_nil
}.should_not raise_error( NoMethodError )
}.should_not raise_error
end

it "should allow setting locked values once" do
Expand Down
2 changes: 1 addition & 1 deletion spec/initializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "should configure threads to abort on exceptions" do
subject.configure_exception_handling

expect( Thread.abort_on_exception ).to be_true
expect( Thread.abort_on_exception ).to be_truthy
end

it "should not configure safely if the gem isn't available" do
Expand Down