-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from guard/rework_logging
Rework logging and UI configuration
- Loading branch information
Showing
18 changed files
with
445 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require "guard/options" | ||
require "guard/ui/logger" | ||
|
||
module Guard | ||
module UI | ||
class Config < Guard::Options | ||
DEFAULTS = { | ||
only: nil, | ||
except: nil, | ||
|
||
# nil (will be whatever $stderr is later) or LumberJack device, e.g. | ||
# $stderr or 'foo.log' | ||
device: nil, | ||
}.freeze | ||
|
||
DEPRECATED_OPTS = %w(template time_format level progname).freeze | ||
|
||
attr_reader :logger_config | ||
|
||
def initialize(options = {}) | ||
opts = Guard::Options.new(options, DEFAULTS) | ||
|
||
# migrate old options stored in UI config directly | ||
deprecated_logger_opts = {} | ||
DEPRECATED_OPTS.each do |option| | ||
if opts.key?(option) | ||
deprecated_logger_opts[option.to_sym] = opts.delete(option) | ||
end | ||
end | ||
|
||
@logger_config = Logger::Config.new(deprecated_logger_opts) | ||
super(opts.to_hash) | ||
end | ||
|
||
def device | ||
# Use strings to work around Thor's indifferent Hash's bug | ||
fetch("device") || $stderr | ||
end | ||
|
||
def only | ||
fetch("only") | ||
end | ||
|
||
def except | ||
fetch("except") | ||
end | ||
|
||
def [](name) | ||
name = name.to_s | ||
|
||
# TODO: remove in Guard 3.x | ||
return logger_config[name] if DEPRECATED_OPTS.include?(name) | ||
return device if name == "device" | ||
|
||
# let Thor's Hash handle anything else | ||
super(name.to_s) | ||
end | ||
|
||
def with_progname(name) | ||
if Guard::UI.logger.respond_to?(:set_progname) | ||
Guard::UI.logger.set_progname(name) do | ||
yield if block_given? | ||
end | ||
elsif block_given? | ||
yield | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "guard/options" | ||
|
||
module Guard | ||
module UI | ||
class Logger | ||
class Config < Guard::Options | ||
DEFAULTS = { | ||
progname: "Guard", | ||
level: :info, | ||
template: ":time - :severity - :message", | ||
time_format: "%H:%M:%S", | ||
flush_seconds: 0, | ||
|
||
# Other LumberJack device-specific options | ||
# max_size: "5M", | ||
# buffer_size: 0, | ||
# additional_lines: nil, | ||
}.freeze | ||
|
||
def initialize(options = {}) | ||
super(options, DEFAULTS) | ||
end | ||
|
||
def level=(value) | ||
self["level"] = value | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.