Logger用于Web服务错误

Logger用于Web服务错误

本文介绍了Sinatra Logger用于Web服务错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 a Sinatra::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 and success in some log file using Sinatra::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服务错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:14