twp / logging-rails Goto Github PK
View Code? Open in Web Editor NEWRailtie for integrating the Logging framework with Rails
Railtie for integrating the Logging framework with Rails
I like a lot logging and also logging-rails due to that. However, I don't particularly like automagical inclusion of "logger" everywhere via ::Logging::Rails::Mixin done in https://github.com/TwP/logging-rails/blob/master/lib/logging/rails/railtie.rb.
While this is not problem with small project, with larger projects is starts to blur things a bit and creates hidden extra dependency.
So I would see beneficial to have option to turn off auto mixin, and have module, which would explicitly include "logger" method in the context.
For example,
class Foobar
include Logging::Log
end
NameError: method `logger' not defined in ActionView::Base
[....]/gems/logging-rails-0.6.0/lib/logging/rails/mixin.rb:18:in `remove_method'
[....]/gems/logging-rails-0.6.0/lib/logging/rails/mixin.rb:18:in `included'
[....]/gems/logging-rails-0.6.0/lib/logging/rails/railtie.rb:35:in `include'
0.5.0 works just fine.
More info here
I understand the READ access, however, I don't understand why it needs WRITE.
When using this gem https://github.com/newrelic/rpm
I got an error when rails is initializing:
/bundle/gems/logging-1.8.2/lib/logging.rb:306: warning: already initialized constant Logging::MAX_LEVEL_LENGTH
/bundle/gems/logging-1.8.2/lib/logging.rb:306: warning: previous definition of MAX_LEVEL_LENGTH was here
/bundle/gems/logging-rails-0.4.0/lib/logging/rails/mixin.rb:21:in `remove_method': method `logger' not defined in ActiveRecord::Base (NameError)
from /bundle/gems/logging-rails-0.4.0/lib/logging/rails/mixin.rb:21:in `included'
from /bundle/gems/logging-rails-0.4.0/lib/logging/rails/railtie.rb:29:in `include'
from /bundle/gems/logging-rails-0.4.0/lib/logging/rails/railtie.rb:29:in `block (2 levels) in <class:Railtie>'
from /bundle/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /bundle/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /bundle/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /bundle/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /bundle/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /bundle/gems/activerecord-4.2.1/lib/active_record/base.rb:316:in `<module:ActiveRecord>'
from /bundle/gems/activerecord-4.2.1/lib/active_record/base.rb:26:in `<top (required)>'
from /bundle/gems/activerecord-4.2.1/lib/active_record/relation/predicate_builder.rb:118:in `<class:PredicateBuilder>'
from /bundle/gems/activerecord-4.2.1/lib/active_record/relation/predicate_builder.rb:2:in `<module:ActiveRecord>'
from /bundle/gems/activerecord-4.2.1/lib/active_record/relation/predicate_builder.rb:1:in `<top (required)>'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies/autoload.rb:70:in `block in eager_load!'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies/autoload.rb:70:in `each_value'
from /bundle/gems/activesupport-4.2.1/lib/active_support/dependencies/autoload.rb:70:in `eager_load!'
from /bundle/gems/activerecord-4.2.1/lib/active_record.rb:158:in `eager_load!'
from /bundle/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in `each'
from /bundle/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
from /bundle/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /bundle/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
from /bundle/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /usr/local/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /usr/local/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /usr/local/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /usr/local/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /usr/local/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /usr/local/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /usr/local/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /bundle/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /bundle/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
from /onelogin/src/config/environment.rb:5:in `<top (required)>'
from /onelogin/src/config.ru:3:in `require'
from /onelogin/src/config.ru:3:in `block in <main>'
from /bundle/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /bundle/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /onelogin/src/config.ru:in `new'
from /onelogin/src/config.ru:in `<main>'
from /bundle/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /bundle/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /bundle/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /bundle/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /bundle/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /bundle/gems/railties-4.2.1/lib/rails/commands/server.rb:61:in `app'
from /bundle/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
By default Rails.logger
is wrapped. When migrating to logging-rails I usually end up doing this. Any reason not to do this in the initializer?
The readme states, this gem is intended for ruby on rails 3, which is outdated at the time of writing this. Is rails 5 support planned?
config.assets.quiet = true
stopped working when I installed the gem
This is a pretty slick gem! I hope that you continue to support it.
One of things that I like to do when logging is to provide the context of the object class and current method caller. For ex:
"WorkerX::a_method - some error went down here"
How can I do this with logging?
Logging.backtrace = true
# somewhere inside a controller
raise StandardError.new("errorz")
After some prying, the format_obj
gets a string representation instead of the raw exception. I assume Rails processes the error before it reaches the logger. Anyone know of a workaround?
This is a great gem, I really like it so far. However I'm seeing one small issue, and I'm not sure if the problem is my config or not.
When I run rake:test
, log statements from the DB preparation get dumped to STDOUT. I have tried setting options in config/environments/test.rb
, but this doesn't seem to make a difference:
# Set the logging destination(s)
config.log_to = %w[]
Here's a (partial) sample run:
davidv@davidv /media/Files/projects/LMS/src/web/trunk $ rake test
[2012-04-10 14:33:00] INFO Rails : New Relic Agent not running.
[2012-04-10 14:33:01] DEBUG ActiveRecord::Base : SQL (0.4ms) SHOW TABLES
[2012-04-10 14:33:01] DEBUG ActiveRecord::Base : SQL (0.3ms) SHOW TABLES
[2012-04-10 14:33:01] DEBUG ActiveRecord::Base : SQL (0.3ms) SELECT `schema_migrations`.`version` FROM `schema_migrations`
[2012-04-10 14:33:01] DEBUG ActiveRecord::Base : SQL (0.4ms) SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'
[2012-04-10 14:33:01] DEBUG ActiveRecord::Base : SQL (0.3ms) SHOW CREATE TABLE `authorization_events`
...
This continues, printing out all the SQL to create the DB. Then the test output prints as normal.
I'm running Rails 3.0.12, Ruby 1.9.3p125, logging-rails 0.4.0, and logging 1.7.2. Running on Linux Mint 9.
Any ideas? Thanks!
10:44:04 web.1 | ! Unable to load application: NoMethodError: undefined method `logger=' for ActiveSupport::Dependencies:Module
10:44:04 web.1 | Did you mean? logger_name
10:44:04 web.1 | /Users/machty/.rvm/gems/ruby-2.3.0-preview1/gems/logging-rails-0.5.0/lib/logging/rails/railtie.rb:39:in `block in <class:Railtie>': undefined method `logger=' for ActiveSupport::Dependencies:Module (NoMethodError)
This initializer seems to be the culprit.
If logger
has been removed from ActiveSupport::Dependencies, what should this initializer attach to in Rails 5? (For posterity, what did setting the logger on AS::Dependencies do in the first place?)
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/server.rb:78:in start': undefined method
formatter' for <Logging::Logger:0x3fdcc4e56bf0 name="Rails">:Logging::Logger (NoMethodError)
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:78:in block in <top (required)>' from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:73:in
tap'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
I'm getting the following error in Rails 3.2.17 (Ruby 1.9.3p448 on Windows 7) when running rails generate logger:install
:
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find activesupport (= 4.0.1) amongst [SyslogLogger-2.0, actionmailer-4.0.1, actionmailer-3.2.17, actionmailer-3.2.16, actionmailer-3.2.15, ac tionmailer-3.2.13, actionpack-4.0.1, actionpack-3.2.17, actionpack-3.2.16, actionpack-3.2.15, actionpack-3.2.13, activemodel-3.2.17, activemodel-3.2.16, activemodel-3.2.3, activerecord-3.2.17, activerecord-3.2.16, activerecord-3. 2.3, activerecord-deprecated_finders-1.0.3, activerecord-jdbc-adapter-1.3.5, activerecord-odbc-adapter-2.0, activerecord-sqlserver-adapter-3.2.12, activerecord-sqlserver-adapter-3.2.10, activerecord-sqlserver-adapter-3.2.4, activ erecord-sqlserver-adapter-2.3.8, activeresource-3.2.17, activeresource-3.2.16, activesupport-4.0.4, activesupport-3.2.17, activesupport-3.2.16, activesupport-3.2.3, acts_as_audited-2.1.0, acts_as_audited-2.0.0, ansi-1.4.3, archiv e-tar-minitar-0.5.2, arel-4.0.1, arel-4.0.0, arel-3.0.3, arel-3.0.2, atomic-1.1.14, awesome_print-1.2.0, barista-1.3.0, bcrypt-ruby-3.1.2-x86-mingw32, better_errors-1.1.0, better_errors-1.0.1, better_errors-0.9.0, better_errors-0 .8.0, bigdecimal-1.1.0, binding_of_caller-0.7.2, binding_of_caller-0.7.1, brakeman-2.4.3, brakeman-2.3.1, brakeman-2.2.0, brakeman-2.1.2, bson-1.9.2, bson-1.8.6, bson_ext-1.9.2, bson_ext-1.8.6, builder-3.1.4, builder-3.0.4, build er-3.0.3, bullet-4.8.0, bullet-4.7.1, bullet-4.6.0, bundler-1.3.5, calendar_helper-0.2.6, calendar_helper-0.2.5, cancan-1.6.10, celluloid-0.15.2, central_logger-0.3.3, childprocess-0.3.9, closure-compiler-1.1.10, closure-compiler -1.1.8, code_analyzer-0.4.5, code_analyzer-0.4.4, code_analyzer-0.4.3, code_analyzer-0.4.2, coderay-1.1.0, coderay-1.0.9, coffee-rails-4.0.1, coffee-rails-3.2.2, coffee-script-2.2.0, coffee-script-source-1.7.0, coffee-script-sour ce-1.6.3, coffee-script-source-1.6.2, colored-1.2, columnize-0.3.6, connection_pool-1.1.0, daemons-1.1.9, dalli-2.7.0, dalli-2.6.4, dalli-2.6.2, dbd-odbc-0.2.5, dbi-0.4.5, debug_inspector-0.0.2, debugger-ruby_core_source-1.2.3, d elayed_job-4.0.0, delayed_job-3.0.5, delayed_job-3.0.0, delayed_job_active_record-4.0.0, delayed_job_active_record-0.4.4, deprecated-2.0.1, devise-3.2.0, devise_ldap_authenticatable-0.8.1, docile-1.1.3, docile-1.1.2, docile-1.1.1 , docile-1.1.0, domain_name-0.5.18, domain_name-0.5.17, domain_name-0.5.15, domain_name-0.5.14, domain_name-0.5.11, erubis-2.7.0, eventmachine-1.0.3-x86-mingw32, eventmachine-1.0.0.beta.4.1-x86-mingw32, execjs-2.0.2, execjs-1.4.0 , fastercsv-1.5.5, fattr-2.2.1, ffi-1.9.3-x86-mingw32, flog-4.1.2, font-awesome-rails-4.0.3.0, font-awesome-rails-3.0.2.0, google_visualr-2.2.0, google_visualr-2.1.9, google_visualr-2.1.7, haml-4.0.5, haml-4.0.4, haml-4.0.3, hash ie-2.0.5, hashie-1.2.0, highline-1.6.21, highline-1.6.20, highline-1.6.19, hike-1.2.3, hike-1.2.2, http-cookie-1.0.2, http-cookie-1.0.1, i18n-0.6.9, i18n-0.6.5, i18n-0.6.1, io-console-0.3, jbuilder-1.5.3, jbuilder-1.5.2, jbuilder -1.4.2, journey-1.0.4, jquery-rails-3.1.0, jquery-rails-3.0.4, jquery-rails-3.0.0, jquery-rails-2.2.1, json-1.8.1, json-1.8.0, json-1.7.7, json-1.5.5, linecache19-0.5.12, little-plugger-1.1.3, lockfile-2.1.0, logging-1.8.2, loggi ng-rails-0.4.0, mail-2.5.4, mail-2.5.3, mechanize-2.7.2, mechanize-2.7.1, method_source-0.8.2, mime-types-1.25.1, mime-types-1.25, mime-types-1.23, mini_portile-0.5.3, mini_portile-0.5.2, minitest-5.3.1, minitest-5.2.2, minitest- 5.0.8, minitest-4.7.5, minitest-4.6.0, minitest-2.5.1, minitest-reporters-1.0.2, minitest-reporters-1.0.0, minitest-reporters-0.14.23, minitest-reporters-0.14.7, mongo-1.9.2, mongo-1.8.6, mongodb_logger-0.6.2, multi_json-1.9.2, m ulti_json-1.8.4, multi_json-1.8.2, multi_json-1.7.6, multi_json-1.7.2, multi_json-1.6.0, mustache-0.99.5, net-http-digest_auth-1.4, net-http-digest_auth-1.3, net-http-persistent-2.9.4, net-http-persistent-2.9.1, net-http-persiste nt-2.9, net-http-persistent-2.8, net-ldap-0.5.1, net-ldap-0.3.1, net-scp-1.0.4, net-ssh-2.2.2, newrelic_rpm-3.7.3.204, newrelic_rpm-3.7.1.188, newrelic_rpm-3.6.9.171, newrelic_rpm-3.6.3.111, newrelic_rpm-3.6.1.87, newrelic_rpm-3. 5.3.25, nokogiri-1.6.1-x86-mingw32, nokogiri-1.6.0-x86-mingw32, nokogiri-1.5.9-x86-mingw32, ntlm-http-0.1.1, opal-0.5.5, open4-1.3.3, open4-1.3.0, orm_adapter-0.4.1, polyglot-0.3.4, polyglot-0.3.3, powerbar-1.0.11, progressbar-0. 21.0, pry-0.9.12.4-x86-mingw32, racc-1.4.10, rack-1.5.2, rack-1.4.5, rack-cache-1.2, rack-protection-1.5.2, rack-ssl-1.3.4, rack-ssl-1.3.3, rack-test-0.6.2, rails-3.2.17, rails-3.2.16, rails_best_practices-1.15.2, rails_best_prac tices-1.14.4, rails_best_practices-1.14.3, railties-4.0.1, railties-3.2.17, railties-3.2.16, railties-3.2.15, railties-3.2.13, rake-10.2.2, rake-10.2.1, rake-10.1.1, rake-10.1.0, rake-10.0.4, rake-0.9.2.2, rdoc-3.12.2, rdoc-3.9.5 , redis-3.0.6, redis-namespace-1.3.2, require_all-1.3.2, require_all-1.3.1, rserve-client-0.3.1, rserve-simpler-0.0.6, ruby-debug-base19x-0.11.30.pre15, ruby-debug-ide-0.4.23.beta1, ruby-debug-ide-0.4.22, ruby-debug-ide-0.4.21, r uby-debug-ide-0.4.21.pre1, ruby-odbc-0.99995, ruby-odbc-0.99992, ruby-ole-1.2.11.6, ruby-ole-1.2.11.4, ruby-progressbar-1.4.2, ruby-progressbar-1.4.1, ruby-progressbar-1.2.0, ruby2ruby-2.0.8, ruby2ruby-2.0.7, ruby2ruby-2.0.6, rub y_core_source-0.1.5, ruby_parser-3.4.1, ruby_parser-3.2.2, sass-3.3.4, sass-3.2.14, sass-3.2.12, sass-3.2.10, sass-3.2.8, sass-rails-4.0.1, sass-rails-3.2.6, sdoc-0.3.20, sexp_processor-4.4.3, sexp_processor-4.4.1, sexp_processor -4.4.0, sexp_processor-4.3.0, sidekiq-2.16.1, simplecov-0.8.2, simplecov-0.8.1, simplecov-0.7.1, simplecov-html-0.8.0, simplecov-html-0.7.1, sinatra-1.4.4, slim-2.0.2, slim-2.0.1, slop-3.4.7, source_map-3.0.1, spreadsheet-0.9.1, spreadsheet-0.8.5, sprockets-2.10.1, sprockets-2.10.0, sprockets-2.2.2, sprockets-rails-2.0.1, sqlite3-1.3.8-x86-mingw32, strong_parameters-0.2.3, strong_parameters-0.2.1, strong_parameters-0.1.4, syslog-logger-1.6.8, temple-0.6. 7, temple-0.6.6, terminal-table-1.4.5, terminator-1.0.0, test-unit-2.5.5, test-unit-2.5.4, thin-1.6.2, thin-1.6.1, thin-1.5.1, thor-0.19.1, thor-0.18.1, thread_safe-0.1.3, tilt-1.4.1, tilt-1.3.7, timers-1.1.0, tiny_tds-0.6.1-x86- mingw32, tiny_tds-0.5.1-x86-mingw32, treetop-1.4.15, treetop-1.4.14, treetop-1.4.12, turbolinks-1.3.1, tzinfo-0.3.39, tzinfo-0.3.38, tzinfo-0.3.37, tzinfo-0.3.35, uglifier-2.3.2, unf-0.1.3, unf-0.1.1, unf_ext-0.0.6-x86-mingw32, u niform_notifier-1.4.0, uniform_notifier-1.3.0, uniform_notifier-1.2.0, vagrant-1.0.7, vegas-0.1.11, warden-1.2.3, webrobots-0.1.1, win32console-1.3.2-x86-mingw32, win32console-1.3.0-x86-mingw32, writeexcel-1.0.4, writeexcel-1.0.3 , writeexcel-1.0.1, xml-simple-1.1.2] (Gem::LoadError) from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:777:in `block in activate_dependencies' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:766:in `each' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:766:in `activate_dependencies' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:750:in `activate' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb:1232:in `gem' from C:/Ruby193/bin/rails:22:in `'
It's looking for actionsupport 4.0.1. Isn't that for Rails 4? Should I be using a specific version of the logging-rails gem for Rails 3?
/home/fernando/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/logging-rails-0.6.0/lib/logging/rails/railtie.rb:18:in block in <class:Railtie>': undefined method
exists?' for File:Class (NoMethodError)
load file if File.exists? file
^^^^^^^^
Did you mean? exist?
from /home/fernando/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/initializable.rb:32:in `instance_exec'
I am using 0.6.0 of this gem + rails 7.0.8.1 and ruby 3.2.2
I think the exists
is removed from ruby 3.0.0 / rails 7.
This is a really nice gem. So nice to see logs being formatted so neatly !
Perhaps this is related to #3 - I'm trying to add more information about where the logging statement was from. Something equivalent to LOG_MSG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(funcName)s(%(lineno)d) : %(message)s'
in python (see my stackoverflow question where someone kindly referred me here)
I thought this was what trace
might do, and managed to turn it on for one of my controllers, but couldn't see any difference in the log file / stdout output.
Did I miss anything?
Also related to the SO question: would be really nice to be able to add the user information (if exists) to the log record for each request. Any pointers on how to achieve something like this will be highly appreciated. Still very new to ruby/rails so apologies if this is the wrong place/a stupid question.
Can logging-rails work in Rails 2.x?
Just came across a strange problem with logging-rails and Unicorn. When unicorn is used with preload_app = true
it spawns worker threads and then logging-rails seem to break. In particular it fails to email errors with the email appender.
A simple solution was to add Logging.reopen
to the after_fork
block in the unicorn config.
Not sure I fully understand what's causing this or how this is prevented, but this small tweak seems to work. If someone can shed some more light on this I'd be most grateful.
I thought I should report this in case this is useful to anybody else who comes across the same issue.
Rails is still using it's logger inside of ActionView
because there is a LogSubscriber
built for it. I end up with a environment.log
file with Rendered ... in xx ms
even though I don't have a file appending enabled in that environment.
Currently, I have the following to override it:
# config/logging.rb
Logging::Rails.configure do |config|
# Typical setup stuff
::Logging::Logger[ActionView::Base].level = config.log_level
end
Rails.application.config.after_initialize do
Rails.application.config.action_view.logger = ::Logging.logger[ActionView::Base]
end
# config/environments/production.rb
Rails.application.configure do
# Other configuration
::Logging::Logger[ActionView::Base].level = :warn
end
Do you think this is something that should be supported in logging-rails
?
I got the following error when I try to run rails after having added the dalli gem (which is a popular gem for performing Caching on rails apps - https://github.com/mperham/dalli).
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/logging-rails-0.4.0/lib/logging/rails/railtie.rb:45:in `block in <class:Railtie>': undefined method `logger=' for #<ActiveSupport::Cache::DalliStore:0x007fcd1c0e6cd0> (NoMethodError)
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `run'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `each'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/application.rb:96:in `initialize!'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/michael/Projects/parcelio/config/environment.rb:5:in `<top (required)>'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/application.rb:83:in `require_environment!'
from /Users/michael/.rvm/gems/ruby-1.9.3-p0@rails313/gems/railties-3.1.3/lib/rails/commands.rb:39:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I checked and saw that it has something to do with the lib/logging/rails/ railtie.rb file:
initializer 'logging.initialize_cache', :after => 'initialize_cache' do
::Rails.cache.logger = ::Logging::Logger[::Rails.cache]
end
And here is what the dalli gem is doing with regards to logging:
def self.logger
@logger ||= (rails_logger || default_logger)
end
def self.rails_logger
(defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
(defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
end
def self.default_logger
require 'logger'
l = Logger.new(STDOUT)
l.level = Logger::INFO
l
end
def self.logger=(logger)
@logger = logger
end
So I basically tried to remove the cache initializer inside your gem, on my fork, but I was unable to get the fork working on my rails app, since logging-rails doesn't have a .gemspec.
Could you maybe point out to a solution (if any is actually possible on your side?)
Thanks
ActiveSupport::OrderedOptions relies on method_missing
to configure a rails application. By default logging-rails monkey patches Object to include Logging.globally
. This makes it impossible to configure loggers:
Rails.configuration.assets.logger = Logging::Logger[Sprockets]
puts Rails.configuration.assets.logger.name # ActiveSupport::OrderedOptions
My current workaround is:
ActiveSupport::OrderedOptions.send :undef_method, :logger
Thank you!
gemspec still shows version 0.5.0
Hi,
ActiveSupport::TaggedLogging
is supposed to be able to wrap "any standard Logger object". However, when wrapping an instance of Logging::Logger
, this does not work:
ActiveSupport::TaggedLogging.new(Logging::Logger.new(STDOUT))
=> NoMethodError: undefined method `formatter=' for #<Logging::Logger:0x007fa3f98c14d8>
This is because ActiveSupport::TaggedLogging
tries to set a formatter in case it doesn't exist.
Since code that tries to wrap the Rails.logger
object in a ActiveSupport::TaggedLogging
instance is becoming more and more common in the rails ecosystem (cf. here in webpacker), this can be deter many users from using this otherwise good framework.
There is a formatter
method already defined in Logging
so maybe it could be possible to map formatter=
to the MDC feature of Logging?
Also, not sure if this should be part of the logging or the logging-rails repo, it has to do with rails but the RailsCompat
module is in the logging repo..
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.