RACK 记录到哪里?
我正在通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这取决于。许多开发人员将其应用程序日志文件定义为 app/servername.log 或仅定义为加载 Rack 应用程序的当前路径。
是的,你可以改变它的路径。
通常您会得到一个 config.ru 文件,其中包含以下内容:
和/或
在本例中,日志文件位于 appdir/sinatra.log 下。但请记住,此代码可以位于 Rack 应用程序中的任何位置,因此请在应用程序目录中查找“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:
and/or
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.
have fun and post here your config.ru and/or the mainprojectfile.rb.
@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.
object_id
最初是相同的,但最好分配给$stderr
。这也让您可以将流返回到最初使用STDERR
的位置:现在是相同的对象。将其发送到其他地方,
$stderr
和STDERR
引用不同的对象。STDERR
仍然流到这里的终端,恢复
$stderr
,我们回来了!
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 withSTDERR
:Same object, for now. Send it elsewhere,
$stderr
andSTDERR
refer to different objects.STDERR
still streams to the terminal here,Restore
$stderr
,And we're back!