Ruby on rails 3.2 SQL消息未记录到从Rails 2.3升级的development.log-in应用程序->;3.2
我正在将一个旧的Rails 2.3应用程序(事实上它甚至更旧)升级到Rails 3.2,我的SQL语句没有被记录到development.log。我电脑上的Rails 3.1应用程序可以很好地记录其SQL语句 我正在使用pow在本地为应用程序提供服务。如果我运行rails服务器,SQL将被输出,但这是因为SQL语句将被输出到STDERR。我检查了logger ActiveRecord使用的是什么(Ruby on rails 3.2 SQL消息未记录到从Rails 2.3升级的development.log-in应用程序->;3.2,ruby-on-rails-3.2,Ruby On Rails 3.2,我正在将一个旧的Rails 2.3应用程序(事实上它甚至更旧)升级到Rails 3.2,我的SQL语句没有被记录到development.log。我电脑上的Rails 3.1应用程序可以很好地记录其SQL语句 我正在使用pow在本地为应用程序提供服务。如果我运行rails服务器,SQL将被输出,但这是因为SQL语句将被输出到STDERR。我检查了logger ActiveRecord使用的是什么(logger.info ActiveRecord::Base.logger.inspect),得到:
logger.info ActiveRecord::Base.logger.inspect
),得到:
#<Logger:0x007fdb9f788688 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007fdb9f788638 @datetime_format=nil>, @formatter=#<Logger::SimpleFormatter:0x007fdb9f788548 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007fdb9f7885e8 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x007fdb9f7885c0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007fdb9f788570>>>>
application.rb
模块MyApp
类应用程序
如果启动console(开发环境),Rails.configuration.log\u级别的输出是什么
现在将ActiveRecord::Base.logger.level与logger::DEBUG(0)、logger::INFO(1)、logger::WARN(2)和logger::ERROR(3)进行比较
如果ActiveRecord::Base.logger.level低于Rails.configuration.log\u级别,那么development.log将不包含来自ActiveRecord的任何SQL日志记录。感谢所有对此进行响应和思考的人。原来有一个2.x时代的库劫持了这个记录器(很天真)。我不知道这个库,因为另一个程序员添加了它。我今天在搜索“Logger.new”时碰巧发现了它,我看到了发生的事情。嗨,pauldoerwald,你能给我更多的细节吗?我们最近从2.3升级到3.1,遇到了同样的问题。我希望你的输入能帮助我们解决问题,或者至少让我们走上正确的方向。对我来说,是Spawn gem/插件覆盖了Logger的定义。一旦我删除了Spawn,日志就开始正常工作了。当然是YMMV,但是如果您在源代码中搜索“Logger.new”,或者通过gems搜索,您可能会发现令人不快的语句。
#<ActiveSupport::BufferedLogger:0x106f28c10 @guard=#<Mutex:0x106ec21b8>, @level=0, @auto_flushing=1, @buffer={}, @log=#<File:/web/unique/dynamic_coupons/log/development.log>>
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for ActiveRecord models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
# Mailer configuration
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { :host => 'lta.dev' }
end
module MyApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
# config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.generators.stylesheet_engine = :sass
end
end