Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging can load initializers first? #21

Open
wbotelhos opened this issue Jun 23, 2015 · 3 comments
Open

Logging can load initializers first? #21

wbotelhos opened this issue Jun 23, 2015 · 3 comments

Comments

@wbotelhos
Copy link

Gemfile:

gem 'logging-rails', require: 'logging/rails'

config/loggin.rb

The original.

config/initializers/logging.rb:

Rails.application.configure do
  if Rails.env.production?
    config.log_to                 = %w[file]
    config.show_log_configuration = false
  else
    config.log_to                 = %w[stdout]
    config.show_log_configuration = true
  end
end

Log configuration:

root  ............................................  *debug      -T
- <Appenders::RollingFile:0x18f397c name="file">
  ActionMailer::Base  ............................   debug  +A  -T
  ActiveRecord::Base  ............................   debug  +A  -T
  ActiveSupport::Cache::FileStore  ...............   debug  +A  -T
  ActiveSupport::Dependencies  ...................   debug  +A  -T
  Logging  .......................................    *off  -A  -T
  Rails  .........................................   debug  +A  -T

I tried to let the config on environments files, but the same effect, the Rails original logging was supressed, but I can't log. I tried:

Rails.logger.error 'foo' # true
Logging::Logger[::Rails].error 'foo' # true
::Logging::Logger[self].error 'foo' # true

The problem is that log?: Logging ....................................... *off -A -T
If yes, What I need more to re-enable Rails logging with my manual one?
How is the logging calling? Rails.logger.xyz?

Thanks you.

@wbotelhos wbotelhos changed the title There is some usage example? How can I call logger as a global method? Jun 23, 2015
@wbotelhos wbotelhos changed the title How can I call logger as a global method? Logging can load initializers first? Jun 23, 2015
@wbotelhos
Copy link
Author

Well,

My problem is the config/logging.rb is called first then initializers, so config.log_to comes with a default (file), not my declared stdout. I used to not change original config files and create initializers to be easier future upgrades. So, there is some way to call config/initializers/logging.rb first then config/logging.rb or a better workaround?

I did a ugly workaround like the following:

Rails.application.configure do
  if Rails.env.production?
    config.log_to                 = %w[file]
    config.show_log_configuration = false
  else
    config.log_to                 = %w[stdout]
    config.show_log_configuration = true
  end

  config.log_level = :debug
end

Logging::Rails.configure do |config|
...

@cmckni3
Copy link
Contributor

cmckni3 commented Apr 26, 2016

Does using Rails.application.config.before_initialize inside of your initializer fix your issue?

You should really only have to set log_to and show_log_configuration in files in config/environments.

I am using a simple initializer with before_initialize to set the log level. I do this because I use the log level specified in the environment variable LOG_LEVEL.

@wbotelhos
Copy link
Author

I set it directly on config to work.
Thank you for the tip, I think it can solve this problem. (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants