Sinatra Logger的Web服务错误
我正在使用Sinatra 1.3
,它是一个Sinatra::Application
。
我有一个获取Web服务的方法。
我想记录此服务何时成功以及它在后台运行时失败的原因(cron作业)
def fetch_some_web_service begin #if successful log.info "Success" rescue SocketError => e log.info "Failed" end end
我似乎无法使用Sinatra
logger instance
。 它为我生成错误,我假设它正在这样做,因为我正在登录一个方法,而不是在一个路径中?
使用Sinatra::Application
捕获某些日志文件中的errors
和success
的最佳方法是什么
我在Sinatra中使用以下代码进行日志记录
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
然后使用记录器进行记录。
logger.info("it works !!!!")