Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyHKafoury committed Oct 8, 2019
1 parent 713b3a4 commit bfdc21a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
module CasAuthenticatedApi
class Application < Rails::Application
# Enable ougai
config.logger = Log::Logger.new(Rails.root.join("log", "datadog.log"))
if Rails.env.development? || Rails.const_defined?("Console")
config.logger = Log::Logger.new(STDOUT)
elsif !Rails.env.test? # use default logger in test env
config.logger = Log::Logger.new(Rails.root.join("log", "datadog.log"))
end
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2

Expand Down
3 changes: 2 additions & 1 deletion lib/log/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Logger < Ougai::Logger
include LoggerSilence

def initialize(*args)
@readable = args[0] == STDOUT
super
after_initialize if respond_to? :after_initialize
end

def create_formatter
if Rails.env.development? || Rails.env.test?
if @readable
Log::Logger::FormatterReadable.new(STDOUT)
else
Log::Logger::Formatter.new(ENV["PROJECT_NAME"])
Expand Down

0 comments on commit bfdc21a

Please sign in to comment.