From 7ebf3956b5304ea8a52ae1f5f94494f089b7e40f Mon Sep 17 00:00:00 2001 From: Michael Kessler Date: Tue, 22 Jan 2013 11:29:40 +0100 Subject: [PATCH] Allow the logger device to be set. --- CHANGELOG.md | 3 ++- README.md | 9 +++++++-- lib/guard/ui.rb | 4 ++-- spec/guard/ui_spec.rb | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a73eb0c0b..093f0b488 100644 --- a/CHANGELOG.md +++ b/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 \ No newline at end of file +[@zonque]: https://github.com/zonque diff --git a/README.md b/README.md index 8bcb86aa9..10dd25ef4 100644 --- a/README.md +++ b/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 diff --git a/lib/guard/ui.rb b/lib/guard/ui.rb index 54c9cf8a7..2d6e36138 100644 --- a/lib/guard/ui.rb +++ b/lib/guard/ui.rb @@ -16,7 +16,7 @@ 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 @@ -24,7 +24,7 @@ def logger # @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 diff --git a/spec/guard/ui_spec.rb b/spec/guard/ui_spec.rb index c91e35c9b..23abb10f2 100644 --- a/spec/guard/ui_spec.rb +++ b/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