[英]Logger fail with Sinatra 1.4.2, Ruby 2.0.0-p195, Passenger 4.0.3 and Rack 1.5.2?
This is my config.ru: 这是我的config.ru:
require 'sinatra'
require 'rack/contrib'
root_dir = File.dirname(__FILE__)
require File.join(root_dir,'app.rb')
set :environment, :development
log = File.new("log/sinatra.log","a+")
$stdout.reopen(log)
$stderr.reopen(log)
$stderr.sync=true
$stdout.sync=true
run Ivende.new
The app.rb: app.rb:
require 'sinatra'
require 'sinatra/reloader'
require 'time'
require 'json'
class Ivende < Sinatra::Application
enable :sessions
set :environment, :development
configure :production do
set :clean_trace,true
end
configure :development do
set :logging, true
end
helpers do
include Rack::Utils
end
require_relative 'models/init'
require_relative 'helpers/init'
require_relative 'routes/init'
end
Inside routes I have this file: 内部路线我有这个文件:
class Ivende < Sinatra::Application
get "/" do
"HOME PAGE "
logger.info("foooooolanito")
end
end
The strange behavior I'm seeing is, when I invoke the main route "/" with the logger line, the explorer shows me the typical passenger error page with the message: 我看到的奇怪行为是,当我用记录器行调用主路线“ /”时,资源管理器向我显示了典型的乘客错误页面,并显示以下消息:
An error occurred while starting up the preloader: it did not write a startup response in time.
In the sinatra.log file I get: 在sinatra.log文件中,我得到:
Ready !> socket:
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10677 !>
!> Ready !> socket:
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10721 !>
!> Ready !> socket:
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10774 !>
!> Ready !> socket:
unix:/tmp/passenger.1.0.10641/generation-0/backends/preloader.10806 !>
Inside the Apache log I get: 在Apache日志中,我得到:
in 'void
Passenger::ApplicationPool2::SmartSpawner::throwPreloaderSpawnException(const
string&, Passenger::SpawnException::ErrorKind,
Passenger::ApplicationPool2::Spawner::BackgroundIOCapturerPtr&, const
DebugDirPtr&)' (SmartSpawner.h:150) in 'std::string
Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)'
(SmartSpawner.h:558) in 'void
Passenger::ApplicationPool2::SmartSpawner::startPreloader()'
(SmartSpawner.h:206) in 'virtual
Passenger::ApplicationPool2::ProcessPtr
Passenger::ApplicationPool2::SmartSpawner::spawn(const
Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744) in 'void
Passenger::ApplicationPool2::Group::spawnThreadRealMain(const
SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned
int)' (Implementation.cpp:695)
[ 2013-05-26 01:36:23.7933 10646/7f6ed6a34700
agents/HelperAgent/RequestHandler.h:1884 ]: [Client 20] Cannot
checkout session. An error occurred while starting up the preloader:
it did not write a startup response in time. [ 2013-05-26
01:36:24.2287 10646/7f6ed8b49700 Pool2/Spawner.h:739 ]: [App 10874
stdout] [ 2013-05-26 01:37:54.1869 10646/7f6ed8b49700
Pool2/Implementation.cpp:762 ]: Could not spawn process for group
/home/dd/dev/ivende/wsapi#default: An error occurred while starting up
the preloader: it did not write a startup response in time. in 'void
Passenger::ApplicationPool2::SmartSpawner::throwPreloaderSpawnException(const
string&, Passenger::SpawnException::ErrorKind,
Passenger::ApplicationPool2::Spawner::BackgroundIOCapturerPtr&, const
DebugDirPtr&)' (SmartSpawner.h:150) in 'std::string
Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)'
(SmartSpawner.h:558) in 'void
Passenger::ApplicationPool2::SmartSpawner::startPreloader()'
(SmartSpawner.h:206) in 'virtual
Passenger::ApplicationPool2::ProcessPtr
Passenger::ApplicationPool2::SmartSpawner::spawn(const
Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744) in 'void
Passenger::ApplicationPool2::Group::spawnThreadRealMain(const
SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned
int)' (Implementation.cpp:695)
[ 2013-05-26 01:37:54.1871 10646/7f6ed6a34700
agents/HelperAgent/RequestHandler.h:1884 ]: [Client 20] Cannot
checkout session. An error occurred while starting up the preloader:
it did not write a startup response in time.
If I remove these lines from my config.ru: 如果我从config.ru中删除这些行:
log = File.new("log/sinatra.log","a+")
$stdout.reopen(log)
$stderr.reopen(log)
$stderr.sync=true
$stdout.sync=true
And: 和:
logger.info("foooooolanito")
Then I see the HOME PAGE text I expect. 然后,我看到了我期望的首页文本。
This project was migrated from a machine that had Ruby 1.9.3-p327, Passenger 3.0.3, Sinatra 1.3.5, where it worked well. 该项目是从运行良好的Ruby 1.9.3-p327,Passenger 3.0.3,Sinatra 1.3.5的计算机上迁移而来的。
What can I do? 我能做什么?
Add these lines in the relevant places: 在相关位置添加以下行:
require "logger"
logger = Log.new("log/sinatra.log","a+")
logger.sync = true
logger.info("foooooolanito")
Basically your get '/'
is fine, but you haven't defined logger
anywhere nor have you require
d logger
. 基本上,您的
get '/'
很好,但是您尚未在任何地方定义logger
,也不require
d logger
。
Let me know if you are thinking something else. 让我知道您是否在想其他事情。
Comment out this line: 注释掉这一行:
$stdout.reopen(log)
I think the cause is that Passenger 4 expects to be able to talk to the workers over STDOUT. 我认为原因是乘客4希望能够通过STDOUT与工人交谈。 However I'm not really sure of the best way to solve the Sinatra logging issue now.
但是,我现在不确定如何解决Sinatra日志记录问题的最佳方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.