Skip to content

Commit

Permalink
Sanity-check logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed May 13, 2018
1 parent 9ae3799 commit 6bdf6ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/controllers/developer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def deploy
redirect_to 'https://travis-ci.org/Undo1/metasmoke-deploy'
end

def query_times_log
send_file 'log/query_times.log'
end

def blank_page
render layout: false
end
Expand Down
1 change: 1 addition & 0 deletions app/views/developer/production_log.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<h3>Developer: production.log</h3>
<p>Take care with the contents of this file - it may contain system or user details.</p>
<p><%= link_to 'Download query times log', dev_query_times_log_path %></p>

<form class="form-inline" method="get" action="<%= dev_prod_log_path %>">
<label for="grep">Search: </label>
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/query_time_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
logger = Logger.new('log/query_times.log')

logger.formatter = proc do |_severity, datetime, _progname, msg|
JSON.generate(time: datetime, msg: msg)
"#{{ time: datetime, path: msg[:path], db_runtime: msg[:db_runtime] }.to_json}\n"
end

ActiveSupport::Notifications.subscribe('process_action.action_controller') do |**info|
logger.info info
logger.info info if SiteSetting['log_query_timings']
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
scope '/dev' do
post 'update_sites', to: 'developer#update_sites', as: :dev_update_sites
get 'prod_log', to: 'developer#production_log', as: :dev_prod_log
get 'query_time_log', to: 'developer#query_times_log', as: :dev_query_times_log
get 'blank', to: 'developer#blank_page', as: :dev_blank
get 'websockets', to: 'developer#websocket_test'
post 'websockets', to: 'developer#send_websocket_test'
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20180513231559_prepare_for_logging_hell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class PrepareForLoggingHell < ActiveRecord::Migration[5.2]
def change
File.delete Rails.root.join('log/query_times.log')
SiteSetting.create name: 'log_query_timings', value_type: 'boolean', value: 0
end
end

0 comments on commit 6bdf6ac

Please sign in to comment.