Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to display Rails' log files in the browser?

This might be (read: probably is) a dumb question, but here goes...

Is there a simple, preferably non third-party, way to display Rails logs in the browser? It gets kind of old opening a log file, then closing it and re-opening it on the next error. It would be superfantastic to just to go domain.tld/logs, which would require user authentication, of course.

like image 844
werm Avatar asked Apr 09 '11 17:04

werm


People also ask

Where can I see rails logs?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.

Where does Rails logger info write to?

By default it puts these log files in the log/ directory of your project. So if you open up that folder you'll see a development.

Where are log files kept?

Most log files are located in the /var/log/ directory. Some applications such as httpd and samba have a directory within /var/log/ for their log files. You may notice multiple files in the log file directory with numbers after them. These are created when the log files are rotated.


1 Answers

For reference, there is a very simple way to do this. However, you would want to protect this page with some sort of authentication/authorization.

Controller:

lines = params[:lines]
if Rails.env == "production"
  @logs = `tail -n #{lines} log/production.log`
else
  @logs = `tail -n #{lines} log/development.log`
end

Log File View:

<pre><%= @logs %></pre>

View to display link:

<%= link_to "log file", log_path(lines: 100) %>

Routes:

get 'logs/:lines' => "pages#log", as: "log"
like image 67
kobaltz Avatar answered Sep 30 '22 22:09

kobaltz