forked from feedjira/feedjira
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 7 commits.
# This is the 1st commit message: Added core logging functionality (feedjira#312) Added core configuration functionality (feedjira#340) # This is the commit message #2: Add convenience Methods for logging Messages (feedjira#312) # This is the commit message feedjira#3: Replace warn with logger (feedjira#312) # This is the commit message feedjira#4: Add logger messages for shadowed exceptions (feedjira#312) # This is the commit message feedjira#5: Enhaced Documentation for LogLevel (feedjira#312) # This is the commit message feedjira#6: Fixed some Logger related issues (feedjira#312) # This is the commit message feedjira#7: Added local DEFAULTS configuration (feedjira#312,feedjira#340)
- Loading branch information
Christian Becker
committed
Dec 19, 2016
1 parent
5a6b1fa
commit b03797d
Showing
9 changed files
with
127 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Feedjira | ||
# Set configuration options by block | ||
# Feedjira.configure do |config| | ||
# config.logger = my_logger_instance | ||
# end | ||
|
||
def self.configure | ||
yield Config | ||
end | ||
|
||
module Config | ||
DEFAULTS = { | ||
logger_io: STDOUT, | ||
logger_level: Logger::WARN | ||
}.freeze | ||
|
||
class << self | ||
def logger=(logger) | ||
Feedjira.logger = logger | ||
end | ||
|
||
def logger | ||
Feedjira.logger | ||
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
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,51 @@ | ||
module Feedjira | ||
class << self | ||
attr_writer :logger | ||
|
||
# Provides a global logger instance for Feedjira | ||
# If no logger is set by the user, a logger using STDOUT is provided | ||
def logger | ||
return @logger unless @logger.nil? | ||
@logger = ::Logger.new(Feedjira::Config::DEFAULTS[:logger_io]) | ||
@logger.level = Feedjira::Config::DEFAULTS[:logger_level] | ||
@logger | ||
end | ||
end | ||
|
||
# Provide some convenience methods for logging | ||
# So the Progname mustn't be passed on every call | ||
# @example | ||
# Feedjira::Logger.info { "My Info Message" } | ||
module Logger | ||
class << self | ||
def debug | ||
Feedjira.logger.debug('Feedjira') { yield } | ||
end | ||
|
||
def info | ||
Feedjira.logger.info('Feedjira') { yield } | ||
end | ||
|
||
def warn | ||
Feedjira.logger.warn('Feedjira') { yield } | ||
end | ||
|
||
def error | ||
Feedjira.logger.error('Feedjira') { yield } | ||
end | ||
|
||
def fatal | ||
Feedjira.logger.fatal('Feedjira') { yield } | ||
end | ||
|
||
# Log exceptions with message and backtrace in a common way | ||
# Exceptions will only be logged when severity level 'debug' is set | ||
def exception(e) | ||
Feedjira.logger.debug('Feedjira') do | ||
msg = block_given? ? "#{yield}\n" : '' | ||
msg + "Message: #{e.message}\n#{e.backtrace.join("\n ")}" | ||
end | ||
end | ||
end | ||
end | ||
end |