问题描述
我正在使用 Sinatra 1.3
,它是一个 Sinatra :: Application
。
I有一种获取Web服务的方法。
当服务成功时,我想要登录,并且在后台运行时失败(cron job)
def fetch_some_web_service
begin
#if success
log.infoSuccess
rescue SocketError => e
log.info失败
end
end
我似乎不能使用 Sinatra
logger instance
。这是为我生成错误,我假设它是这样做的,因为我正在登录一个方法,而不是在一个路线?
什么是最好的方式来捕获某些日志文件中使用错误
和成功
Sinatra :: Application
我在Sinatra中使用以下代码进行日志记录
<$ p如果log_file_location == nil
log_file = File.new(log_file_location,a)$ p $
raiselog file not specified
$ stdout.reopen log_file)
$ stderr.reopen(log_file)
$ stdout.sync = true
$ stderr.sync = true
然后使用记录器进行日志记录。
logger.info(it works !!!!)
pre>
I am using
Sinatra 1.3
and it's aSinatra::Application
.
I have a method that fetches a web service.
I want to log when this service has succeed and what it has failed as it runs in the background (cron job)def fetch_some_web_service begin #if successful log.info "Success" rescue SocketError => e log.info "Failed" end end
I can't seem to use the
Sinatra
logger instance
. It's generating errors for me and I'm assuming it's doing this because I'm logging in a method and not within a route?What is the best way to capture the
errors
andsuccess
in some log file usingSinatra::Application
解决方案I use the following code in Sinatra for logging
raise "Log File not specified" if log_file_location == nil log_file = File.new(log_file_location, "a") $stdout.reopen(log_file) $stderr.reopen(log_file) $stdout.sync=true $stderr.sync=true
Then use logger to log.
logger.info("it works !!!!")
这篇关于Sinatra Logger用于Web服务错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!