Ruby-on-rails 我们如何查看Rails 开发日志?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1015739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can we watch the Rails development log?
提问by Ethan
A member of my team is developing a Rails app on Windows XP. We are finding that when we run the app, either launching it within NetBeans or by opening a console and calling script/server, the Rails development log does not scroll by. There is only the Webrick startup message. The app is definitely running, but when we hit various pages in the browser we aren't seeing any logging output.
我团队的一名成员正在 Windows XP 上开发 Rails 应用程序。我们发现当我们运行应用程序时,无论是在 NetBeans 中启动它还是通过打开控制台并调用script/server,Rails 开发日志都不会滚动。只有 Webrick 启动消息。该应用程序肯定正在运行,但是当我们在浏览器中点击各个页面时,我们没有看到任何日志输出。
When I look at the identical app on my OS X system, logging output works as expected.
当我在 OS X 系统上查看相同的应用程序时,日志输出按预期工作。
I did make sure that it's running in Rails "development" environment.
我确实确保它在 Rails“开发”环境中运行。
Any ideas why logging would be suppressed?
任何想法为什么会抑制日志记录?
Are there config params for the environment.rb file that would affect it?
是否有影响它的 environment.rb 文件的配置参数?
回答by Sarah Mei
Look in the log/directory - there should be a development.log. I bet your output is there.
查看log/目录 - 应该有一个development.log. 我敢打赌你的输出就在那里。
If it's not, make sure that directory is writable.
如果不是,请确保该目录可写。
For how to see it while you're running: if you have git bash installed, or some other shell such as cygwin, then you can open a shell and do tail -f log/development.logwhich will scroll the log as it gets stuff appended to it.
关于如何在运行时查看它:如果您安装了 git bash 或其他一些 shell,例如 cygwin,那么您可以打开一个 shell 并执行tail -f log/development.log它会滚动日志,因为它会附加一些内容。
回答by Andres Jaan Tack
The Rails Configurationdocumentation suggests that you may have log_levelset to something other than :debugin your configuration.
在Rails的配置文件表明,你可能已经log_level设置为比其他的东西:debug在你的配置。
There is also an alternative place to view the requests: the log/development.log file in your Rails app. If nothing is written there, then your problem must be in configuration. On a *nix system I would run:
还有一个替代位置可以查看请求:Rails 应用程序中的 log/development.log 文件。如果那里没有写任何内容,那么您的问题一定出在配置中。在 *nix 系统上,我会运行:
$ tail -f log/development.log
And watch the requests run by. They tell me that there is a Windows version of tail.
并观察运行的请求。他们告诉我有一个Windows 版本的tail.
回答by Tu H.
less -R log/development.log
I just started to use this.
我刚开始用这个。
回答by Rahul2692
Try this, to get development log:
试试这个,获取开发日志:
tail -f log/development.log
Make sure that you are in the application path.
确保您在应用程序路径中。
回答by Thiago Arrais
I always use log/development.logto look at the logs. Just tail -fit using cygwin or something.
我总是习惯log/development.log看日志。只是tail -f使用 cygwin 或其他东西。
Maybe your Windows environment is using WEBrick and the OS X environment is using Mongrel or other webserver. I've noticed that with some webservers the logging output is (also) written directly into the shell and with others is written only to the log files.
也许您的 Windows 环境使用 WEBrick,而 OS X 环境使用 Mongrel 或其他网络服务器。我注意到,对于某些网络服务器,日志输出(也)直接写入外壳程序,而其他网络服务器仅写入日志文件。
回答by srboisvert
Netbeans seems to stop displaying the dev log in the console window when the dev log gets too large. At least that was my experience.
当开发日志变得太大时,Netbeans 似乎停止在控制台窗口中显示开发日志。至少这是我的经验。
回答by Mike Woodhouse
Without digging into the source for Webrick, I suspect that the amount of information displayed is by default not large. Are you sure you're running Webrick on OSX and not Mongrel?
没有深入研究 Webrick 的来源,我怀疑默认显示的信息量并不大。你确定你在 OSX 上运行 Webrick 而不是 Mongrel?
In fact, is there a particular reason for continuing to use Webrick at all? Before the advent of Phusion Passenger, Mongrel had become the de factofront-end server of choice, and it works just fine on Windows. If you install it (gem install mongrel) then Rails will use it by default.
事实上,继续使用 Webrick 有什么特别的理由吗?在 Phusion Passenger 出现之前,Mongrel 已经成为事实上的首选前端服务器,并且它在 Windows 上运行良好。如果您安装它 ( gem install mongrel),那么 Rails 将默认使用它。
In my development environment, running Webrick (after I'd figured out how - it's been a long time) I got very brief output: just a record of the "GET" request. Switching to Mongrel, I got the full works: request, parameters, SQL, timings etc.
在我的开发环境中,运行 Webrick(在我弄清楚如何 - 已经很长时间之后)我得到了非常简短的输出:只是“GET”请求的记录。切换到 Mongrel,我得到了完整的工作:请求、参数、SQL、计时等。
回答by Hristo
I use tail with grep
我在 grep 中使用 tail
tail -f log/development.log | grep Started -A 1
Works beautifully.
工作精美。
回答by Sumit Munot
You can see the run-time logs using the below command:
您可以使用以下命令查看运行时日志:
tailf log/development.log
Also if you just want first or last number of lines from the logs you can just get those using below command (first / last 100 lines from logs):
此外,如果您只想要日志中的第一行或最后一行,您可以使用以下命令获取这些行(日志中的第一行/最后 100 行):
For example:
例如:
First 100 lines:
前 100 行:
head -n 100 log/development.log
Last 100 lines:
最后 100 行:
tail -n 100 log/development.log
Thanks!
谢谢!
回答by Foram Thakral
You can try this command
你可以试试这个命令
$ tail -f development.log
$ tail -f log/development.log

