Browse files

Allow the logger device to be set.

  • Loading branch information...
1 parent c8b8b6b commit 7ebf3956b5304ea8a52ae1f5f94494f089b7e40f @netzpirat netzpirat committed Jan 22, 2013
Showing with 16 additions and 6 deletions.
  1. +2 −1 CHANGELOG.md
  2. +7 −2 README.md
  3. +2 −2 lib/guard/ui.rb
  4. +5 −1 spec/guard/ui_spec.rb
View
3 CHANGELOG.md
@@ -2,6 +2,7 @@
### Improvements
+- Allow the logger device to be set with the `:device` option.
- Improve `list` and `show` command output. ([@netzpirat][])
- [#386][] Replace Pry's reset command. ([@envygeeks][])
@@ -803,4 +804,4 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@waldo]: https://github.com/waldo
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
-[@zonque]: https://github.com/zonque
+[@zonque]: https://github.com/zonque
View
9 README.md
@@ -795,14 +795,16 @@ filter /\.js$/
### logger
-The `logger` method allows you to customize the Guard log output to your needs by specifying one or more options like:
+The `logger` method allows you to customize the [Lumberjack](https://github.com/bdurand/lumberjack) log output to your
+needs by specifying one or more options like:
```ruby
logger :level => :warn,
:template => '[:severity - :time - :progname] :message',
:time_format => 'at %I:%M%p',
:only => [:rspec, :jasmine, 'coffeescript'],
- :except => :jammit
+ :except => :jammit,
+ :device => 'guard.log'
```
Log `:level` option must be either `:debug`, `:info`, `:warn` or `:error`. If Guard is started in debug mode, the log
@@ -817,6 +819,9 @@ The `:time_format` option directives are the same as Time#strftime or can be `:m
The `:only` and `:except` are either a string or a symbol, or an array of strings or symbols that matches the name of
the Guard plugin name that sends the log message. They cannot be specified at the same time.
+By default the logger uses `$stderr` as device, but you can override this by supplying the `:device` option and set
+either an IO stream or a filename.
+
### Example
```ruby
View
4 lib/guard/ui.rb
@@ -16,15 +16,15 @@ class << self
# Get the Guard::UI logger instance
#
def logger
- @logger ||= Lumberjack::Logger.new($stderr, self.options)
+ @logger ||= Lumberjack::Logger.new(self.options[:device], self.options)
end
# Get the logger options
#
# @return [Hash] the logger options
#
def options
- @options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' }
+ @options ||= { :device => $stderr, :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' }
end
# Set the logger options
View
6 spec/guard/ui_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Guard::UI do
- after { Guard::UI.options = { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } }
+ after { Guard::UI.options = { :level => :info, :device => $stderr, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } }
before do
# The spec helper stubs all UI classes, so other specs doesn't have
@@ -32,6 +32,10 @@
it 'returns the logger instance' do
Guard::UI.logger.should be_an_instance_of Lumberjack::Logger
end
+
+ it 'sets the logger device' do
+ Guard::UI.logger.device.send(:stream).should be $stderr
+ end
end
describe '.options=' do

0 comments on commit 7ebf395

Please sign in to comment.