Skip to content

Commit

Permalink
Merge pull request #140 from bundler/allow-stdout-logging
Browse files Browse the repository at this point in the history
Allow stdout logging when running --no-daemonize
  • Loading branch information
smellsblue committed Mar 15, 2017
2 parents da1c178 + 3c92827 commit e5351bc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/gemstash-configuration.5.md
Expand Up @@ -228,4 +228,6 @@ Default value
Valid values
------------

Any valid file name
Any valid file name, or `:stdout` to log to `$stdout`

*Note: Using `:stdout` for the `:log_file` requires [running with `--no-daemonize`](gemstash-start.1.md#options).*
6 changes: 5 additions & 1 deletion lib/gemstash/env.rb
Expand Up @@ -97,7 +97,11 @@ def base_file(path)
end

def log_file
base_file(config[:log_file] || "server.log")
if config[:log_file] == :stdout
$stdout
else
base_file(config[:log_file] || "server.log")
end
end

def atomic_write(file, &block)
Expand Down
5 changes: 4 additions & 1 deletion man/gemstash-configuration.5.md
Expand Up @@ -222,10 +222,13 @@ the [base path][BASE_PATH].

## Valid values

Any valid file name
Any valid file name, or `:stdout` to log to `$stdout`

*Note: Using `:stdout` for the `:log_file` requires [running with `--no-daemonize`][NO_DAEMONIZE].*

[SETUP]: ./gemstash-setup.1.md
[SEQUEL]: http://sequel.jeremyevans.net/
[SEQUEL_CONNECT]: http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html#label-General+connection+options
[PUMA_BINDING]: https://github.com/puma/puma#binding-tcp--sockets
[BASE_PATH]: ./gemstash-configuration.5.md#base-path
[NO_DAEMONIZE]: ./gemstash-start.1.md#options
22 changes: 22 additions & 0 deletions spec/gemstash/env_spec.rb
@@ -1,6 +1,28 @@
require "spec_helper"

describe Gemstash::Env do
context ".log_file" do
let(:dir) { __dir__ }

it "has a default log file path" do
config = Gemstash::Configuration.new(config: { base_path: dir })
env = Gemstash::Env.new(config)
expect(env.log_file).to eq(File.join(dir, "server.log"))
end

it "supports a customized log file path" do
config = Gemstash::Configuration.new(config: { base_path: dir, log_file: "my_log.log" })
env = Gemstash::Env.new(config)
expect(env.log_file).to eq(File.join(dir, "my_log.log"))
end

it "supports :stdout from config to obtain standard out" do
config = Gemstash::Configuration.new(config: { log_file: :stdout })
env = Gemstash::Env.new(config)
expect(env.log_file).to eq($stdout)
end
end

context "with a base path other than default" do
let(:env) { Gemstash::Env.new }

Expand Down

0 comments on commit e5351bc

Please sign in to comment.