mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
logster integration (in production as well)
This commit is contained in:
parent
e9de700dca
commit
4af0aa9cbc
8 changed files with 52 additions and 16 deletions
5
Gemfile
5
Gemfile
|
@ -222,8 +222,9 @@ gem 'simple-rss', require: false
|
|||
gem 'gctools', require: false, platform: :mri_21
|
||||
gem 'stackprof', require: false, platform: :mri_21
|
||||
|
||||
# Disabled as it conflicts with our /admin/logs routes
|
||||
# gem 'logster'
|
||||
# This silly path comment just makes it easier for me to do dev
|
||||
# will be removed in a few weeks
|
||||
gem 'logster'#, path: '/home/sam/Source/logster'
|
||||
|
||||
# perftools only works on 1.9 atm
|
||||
group :profile do
|
||||
|
|
|
@ -151,6 +151,7 @@ GEM
|
|||
thor (~> 0.15)
|
||||
libv8 (3.16.14.3)
|
||||
listen (0.7.3)
|
||||
logster (0.0.3)
|
||||
lru_redux (0.8.1)
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
|
@ -417,6 +418,7 @@ DEPENDENCIES
|
|||
image_sorcery
|
||||
librarian (>= 0.0.25)
|
||||
listen (= 0.7.3)
|
||||
logster
|
||||
lru_redux
|
||||
message_bus
|
||||
minitest
|
||||
|
|
|
@ -128,8 +128,11 @@ module Discourse
|
|||
config.handlebars.templates_root = 'discourse/templates'
|
||||
|
||||
require 'discourse_redis'
|
||||
require 'logster/redis_store'
|
||||
# Use redis for our cache
|
||||
config.cache_store = DiscourseRedis.new_redis_store
|
||||
$redis = DiscourseRedis.new
|
||||
Logster.store = Logster::RedisStore.new($redis)
|
||||
|
||||
# we configure rack cache on demand in an initializer
|
||||
# our setup does not use rack cache and instead defers to nginx
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
require "#{Rails.root}/lib/discourse_redis"
|
||||
|
||||
$redis = DiscourseRedis.new
|
||||
|
||||
if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS']
|
||||
puts "Flushing redis (development mode)"
|
||||
$redis.flushall
|
||||
|
@ -16,3 +12,4 @@ if defined?(PhusionPassenger)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,13 +16,15 @@ if defined?(Rack::MiniProfiler)
|
|||
|
||||
# For our app, let's just show mini profiler always, polling is chatty so nuke that
|
||||
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
|
||||
path = env['PATH_INFO']
|
||||
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7|Android/) &&
|
||||
(env['PATH_INFO'] !~ /^\/message-bus/) &&
|
||||
(env['PATH_INFO'] !~ /topics\/timings/) &&
|
||||
(env['PATH_INFO'] !~ /assets/) &&
|
||||
(env['PATH_INFO'] !~ /qunit/) &&
|
||||
(env['PATH_INFO'] !~ /srv\/status/) &&
|
||||
(env['PATH_INFO'] !~ /commits-widget/)
|
||||
(path !~ /^\/message-bus/) &&
|
||||
(path !~ /topics\/timings/) &&
|
||||
(path !~ /assets/) &&
|
||||
(path !~ /qunit/) &&
|
||||
(path !~ /srv\/status/) &&
|
||||
(path !~ /commits-widget/) &&
|
||||
(path !~ /^\/logs\/messages/)
|
||||
end
|
||||
|
||||
# without a user provider our results will use the ip address for namespacing
|
||||
|
|
|
@ -42,3 +42,19 @@ if Sidekiq.server?
|
|||
end
|
||||
|
||||
Sidekiq.logger.level = Logger::WARN
|
||||
|
||||
class LogsterErrorHandler
|
||||
def call(ex, hash={})
|
||||
text = "exception: #{ex}\ncontext: #{hash.inspect}\n"
|
||||
if ex.backtrace
|
||||
text << "backtrace: #{ex.backtrace.join("\n")}"
|
||||
end
|
||||
Rails.logger.error(text)
|
||||
rescue => e
|
||||
Rails.logger.fatal("Failed to log exception #{ex} #{hash}\nReason: #{e}\n#{e.backtrace.join("\n")}")
|
||||
end
|
||||
end
|
||||
|
||||
Sidekiq.error_handlers << LogsterErrorHandler.new
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class SilenceLogger < Rails::Rack::Logger
|
||||
PATH_INFO = 'PATH_INFO'.freeze
|
||||
HTTP_X_SILENCE_LOGGER = 'HTTP_X_SILENCE_LOGGER'.freeze
|
||||
|
||||
def initialize(app, opts = {})
|
||||
@app = app
|
||||
@opts = opts
|
||||
|
@ -10,11 +13,13 @@ class SilenceLogger < Rails::Rack::Logger
|
|||
|
||||
def call(env)
|
||||
prev_level = Rails.logger.level
|
||||
path_info = env[PATH_INFO]
|
||||
|
||||
if env['HTTP_X_SILENCE_LOGGER'] || @opts[:silenced].include?(env['PATH_INFO'])
|
||||
if env[HTTP_X_SILENCE_LOGGER] ||
|
||||
@opts[:silenced].include?(path_info) ||
|
||||
path_info.start_with?('/logs')
|
||||
Rails.logger.level = Logger::WARN
|
||||
result = @app.call(env)
|
||||
result
|
||||
@app.call(env)
|
||||
else
|
||||
super(env)
|
||||
end
|
||||
|
@ -23,5 +28,10 @@ class SilenceLogger < Rails::Rack::Logger
|
|||
end
|
||||
end
|
||||
|
||||
silenced = ["/mini-profiler-resources/results", "/mini-profiler-resources/includes.js", "/mini-profiler-resources/includes.css", "/mini-profiler-resources/jquery.tmpl.js"]
|
||||
silenced = [
|
||||
"/mini-profiler-resources/results".freeze,
|
||||
"/mini-profiler-resources/includes.js".freeze,
|
||||
"/mini-profiler-resources/includes.css".freeze,
|
||||
"/mini-profiler-resources/jquery.tmpl.js".freeze
|
||||
]
|
||||
Rails.configuration.middleware.swap Rails::Rack::Logger, SilenceLogger, silenced: silenced
|
||||
|
|
|
@ -16,6 +16,11 @@ Discourse::Application.routes.draw do
|
|||
|
||||
mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new
|
||||
|
||||
if Rails.env.production?
|
||||
require 'logster/middleware/viewer'
|
||||
mount Logster::Middleware::Viewer.new(nil) => "/logs", constraints: AdminConstraint.new
|
||||
end
|
||||
|
||||
get "site" => "site#index"
|
||||
|
||||
resources :forums
|
||||
|
|
Loading…
Reference in a new issue