-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use SemanticLogger for Padrino (#662)
- Loading branch information
Showing
4 changed files
with
27 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
require "pact_broker/configuration" | ||
# Must be defined before loading Padrino | ||
# Stop Padrino creating a log file, as it will try to create it in the gems directory | ||
# http://www.padrinorb.com/api/Padrino/Logger.html | ||
unless defined? PADRINO_LOGGER | ||
log_path = File.join(PactBroker.configuration.log_dir, "ui.log") | ||
PADRINO_LOGGER = { | ||
production: { log_level: :error, stream: :to_file, log_path: log_path }, | ||
staging: { log_level: :error, stream: :to_file, log_path: log_path }, | ||
test: { log_level: :warn, stream: :to_file, log_path: log_path }, | ||
development: { log_level: :warn, stream: :to_file, log_path: log_path } | ||
} | ||
# This configuration will be replaced by the SemanticLogger later on. | ||
PADRINO_LOGGER ||= { | ||
ENV.fetch("RACK_ENV", "production").to_sym => { stream: :stdout } | ||
} | ||
|
||
require "padrino-core" | ||
|
||
class PactBrokerPadrinoLogger < SemanticLogger::Logger | ||
include Padrino::Logger::Extensions | ||
|
||
# Padrino expects level to return an integer, not a symbol | ||
def level | ||
Padrino::Logger::Levels[SemanticLogger.default_level] | ||
end | ||
end | ||
|
||
Padrino.logger = PactBrokerPadrinoLogger.new("Padrino") | ||
# Log a test message to ensure that the logger works properly, as it only | ||
# seems to be used in production. | ||
Padrino.logger.info("Padrino has been configured with SemanticLogger") | ||
|
||
require "pact_broker/ui/app" |
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