Is there a way to display Rails log files in a browser?

It may be (read: maybe there is) a dumb question, but here goes ...

Is there a simple rather than a third-party way to display Rails logs in a browser? It takes the form of an old opening of a log file, then closes it and reopens it with the next error. It would be super-fun to just go domain.tld/logs , which would require user authentication, of course.

+4
source share
3 answers

All you need to do is open the log file and put its contents into the browser.

Implemented topic: ruby: all methods of reading from a file .

You should also be aware that your logs are growing very fast, and it is not recommended that you display the entire log in a browser. You can simply open the last 100-200 lines. Related topic: Reading the last n lines in Ruby?

You can also try this solution: http://newrelic.com/ . It is more complex and small format, but very useful.

+7
source

For reference, there is a very easy way to do this. However, you will want to protect this page with some kind 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 

View log file:

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

View image link:

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

Routes

 get 'logs/:lines' => "pages#log", as: "log" 
+11
source

I created a browserlog for this purpose.

Installation is just a matter of adding a gem to the Gemfile:

 gem 'browserlog' 

Subsequently, all you need is to mount the engine along the desired route:

 MyApp::Application.routes.draw do mount Browserlog::Engine => '/logs' end 

After this setting, access / logs / development (or production, test, etc.) will display the following window:

browserlog_screenshot http://andredieb.com/assets/images/browserlog1.png

+5
source

Source: https://habr.com/ru/post/1347370/


All Articles