RACK 记录到哪里?

发布于 2024-08-23 12:11:31 字数 66 浏览 5 评论 0原文

我正在通过 RACK 运行 sinatra 应用程序。

活动记录到哪个文件?另外如何设置日志文件路径?

I am running a sinatra app through RACK.

To which file does the activity get logged ? Also how can I set the log file path ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇纵 2024-08-30 12:11:31

这取决于。许多开发人员将其应用程序日志文件定义为 app/servername.log 或仅定义为加载 Rack 应用程序的当前路径。

是的,你可以改变它的路径。

通常您会得到一个 config.ru 文件,其中包含以下内容:

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

    # optionally to sync logs while the server is running
    $stderr.sync = true
    $stdout.sync = true

和/或

    configure do
      LOGGER = Logger.new("sinatra.log")
      enable :logging, :dump_errors
      set :raise_errors, true
    end

在本例中,日志文件位于 appdir/sinatra.log 下。但请记住,此代码可以位于 Rack 应用程序中的任何位置,因此请在应用程序目录中查找“log”。

    $ cd projectname
    $ grep -ri 'log' *

玩得开心并在此处发布您的 config.ru 和/或 mainprojectfile.rb。

It depends. Many developers define their app log file to app/servername.log or just to the current path where the Rack app is loaded.

Yes you can change it's path.

Usually you get a config.ru file with something like:

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

    # optionally to sync logs while the server is running
    $stderr.sync = true
    $stdout.sync = true

and/or

    configure do
      LOGGER = Logger.new("sinatra.log")
      enable :logging, :dump_errors
      set :raise_errors, true
    end

in this case the log file is located under appdir/sinatra.log. But remember this code can be anywhere in your Rack app, so please seek for "log" in your application directory.

    $ cd projectname
    $ grep -ri 'log' *

have fun and post here your config.ru and/or the mainprojectfile.rb.

空宴 2024-08-30 12:11:31

@include 上面的答案LOGGER = Logger.new("sinatra.log") 行> 不适合我。

不过,此处列出了替代方案(以及一些有用的信息)解释)对我有用,用 ruby​​ 2.5.3 和 sinatra 2.0.1 进行测试。

有关更多信息,该替代方案基于 Sinatra 配方 中提供的结构。

The line of LOGGER = Logger.new("sinatra.log") in @include's answer above did not work for me.

However, an alternative listed here (along with some helpful explanations) worked for me, tested with ruby 2.5.3 and sinatra 2.0.1.

For additional info, that alternative is based on the structure presented in a Sinatra recipe.

失去的东西太少 2024-08-30 12:11:31

object_id 最初是相同的,但最好分配给 $stderr。这也让您可以将流返回到最初使用 STDERR 的位置:

 $ irb
>> $stderr.object_id == STDERR.object_id
=> true

现在是相同的对象。将其发送到其他地方,

>> $stderr = File.open('/tmp/foo', 'w')
=> #<File:/tmp/foo>
>> $stderr.puts "Uh-oh, foo"
=> nil
>> $stderr.flush    # if you want to verify its output
=> #<File:/tmp/foo>
>> $stderr.object_id == STDERR.object_id
=> false

$stderrSTDERR 引用不同的对象。 STDERR 仍然流到这里的终端,

>> STDERR.puts "Uh-oh, original STDERR"
Uh-oh, original STDERR
=> nil

恢复 $stderr

>> $stderr = STDERR
=> #<IO:0x106fddb88>
>> $stderr.object_id == STDERR.object_id
=> true

我们回来了!

The object_id are initially the same but it's better to assign to $stderr. That also leaves you open to return the stream to where it was originally with STDERR:

 $ irb
>> $stderr.object_id == STDERR.object_id
=> true

Same object, for now. Send it elsewhere,

>> $stderr = File.open('/tmp/foo', 'w')
=> #<File:/tmp/foo>
>> $stderr.puts "Uh-oh, foo"
=> nil
>> $stderr.flush    # if you want to verify its output
=> #<File:/tmp/foo>
>> $stderr.object_id == STDERR.object_id
=> false

$stderr and STDERR refer to different objects. STDERR still streams to the terminal here,

>> STDERR.puts "Uh-oh, original STDERR"
Uh-oh, original STDERR
=> nil

Restore $stderr,

>> $stderr = STDERR
=> #<IO:0x106fddb88>
>> $stderr.object_id == STDERR.object_id
=> true

And we're back!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文