1

这是我的 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

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

内部路线我有这个文件:

class Ivende < Sinatra::Application

get "/" do
"HOME PAGE "
logger.info("foooooolanito")
end
end

我看到的奇怪行为是,当我使用记录器行调用主路线“/”时,资源管理器向我显示典型的乘客错误页面,并显示以下消息:

An error occurred while starting up the preloader: it did not write a startup response in time.

在 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 !>

在 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.

如果我从 config.ru 中删除这些行:

log = File.new("log/sinatra.log","a+") 
$stdout.reopen(log) 
$stderr.reopen(log) 
$stderr.sync=true 
$stdout.sync=true

和:

logger.info("foooooolanito")

然后我看到了我期望的主页文本。

这个项目是从一台安装了 Ruby 1.9.3-p327、Passenger 3.0.3、Sinatra 1.3.5 的机器上迁移过来的,它运行良好。

我能做些什么?

4

2 回答 2

0

注释掉这一行:

$stdout.reopen(log)

我认为原因是乘客 4 期望能够通过 STDOUT 与工人交谈。但是,我现在不确定解决 Sinatra 日志记录问题的最佳方法。

于 2013-06-19T20:35:18.943 回答
0

在相关位置添加这些行:

require "logger"

logger = Log.new("log/sinatra.log","a+")
logger.sync = true

logger.info("foooooolanito")

基本上你get '/'的很好,但你没有logger在任何地方定义,也没有required logger

如果你在想别的事情,请告诉我。

于 2013-05-27T15:38:20.297 回答