mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -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 'gctools', require: false, platform: :mri_21
|
||||||
gem 'stackprof', require: false, platform: :mri_21
|
gem 'stackprof', require: false, platform: :mri_21
|
||||||
|
|
||||||
# Disabled as it conflicts with our /admin/logs routes
|
# This silly path comment just makes it easier for me to do dev
|
||||||
# gem 'logster'
|
# will be removed in a few weeks
|
||||||
|
gem 'logster'#, path: '/home/sam/Source/logster'
|
||||||
|
|
||||||
# perftools only works on 1.9 atm
|
# perftools only works on 1.9 atm
|
||||||
group :profile do
|
group :profile do
|
||||||
|
|
|
@ -151,6 +151,7 @@ GEM
|
||||||
thor (~> 0.15)
|
thor (~> 0.15)
|
||||||
libv8 (3.16.14.3)
|
libv8 (3.16.14.3)
|
||||||
listen (0.7.3)
|
listen (0.7.3)
|
||||||
|
logster (0.0.3)
|
||||||
lru_redux (0.8.1)
|
lru_redux (0.8.1)
|
||||||
mail (2.5.4)
|
mail (2.5.4)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
|
@ -417,6 +418,7 @@ DEPENDENCIES
|
||||||
image_sorcery
|
image_sorcery
|
||||||
librarian (>= 0.0.25)
|
librarian (>= 0.0.25)
|
||||||
listen (= 0.7.3)
|
listen (= 0.7.3)
|
||||||
|
logster
|
||||||
lru_redux
|
lru_redux
|
||||||
message_bus
|
message_bus
|
||||||
minitest
|
minitest
|
||||||
|
|
|
@ -128,8 +128,11 @@ module Discourse
|
||||||
config.handlebars.templates_root = 'discourse/templates'
|
config.handlebars.templates_root = 'discourse/templates'
|
||||||
|
|
||||||
require 'discourse_redis'
|
require 'discourse_redis'
|
||||||
|
require 'logster/redis_store'
|
||||||
# Use redis for our cache
|
# Use redis for our cache
|
||||||
config.cache_store = DiscourseRedis.new_redis_store
|
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
|
# we configure rack cache on demand in an initializer
|
||||||
# our setup does not use rack cache and instead defers to nginx
|
# 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']
|
if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS']
|
||||||
puts "Flushing redis (development mode)"
|
puts "Flushing redis (development mode)"
|
||||||
$redis.flushall
|
$redis.flushall
|
||||||
|
@ -16,3 +12,4 @@ if defined?(PhusionPassenger)
|
||||||
end
|
end
|
||||||
end
|
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
|
# 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|
|
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
|
||||||
|
path = env['PATH_INFO']
|
||||||
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7|Android/) &&
|
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7|Android/) &&
|
||||||
(env['PATH_INFO'] !~ /^\/message-bus/) &&
|
(path !~ /^\/message-bus/) &&
|
||||||
(env['PATH_INFO'] !~ /topics\/timings/) &&
|
(path !~ /topics\/timings/) &&
|
||||||
(env['PATH_INFO'] !~ /assets/) &&
|
(path !~ /assets/) &&
|
||||||
(env['PATH_INFO'] !~ /qunit/) &&
|
(path !~ /qunit/) &&
|
||||||
(env['PATH_INFO'] !~ /srv\/status/) &&
|
(path !~ /srv\/status/) &&
|
||||||
(env['PATH_INFO'] !~ /commits-widget/)
|
(path !~ /commits-widget/) &&
|
||||||
|
(path !~ /^\/logs\/messages/)
|
||||||
end
|
end
|
||||||
|
|
||||||
# without a user provider our results will use the ip address for namespacing
|
# without a user provider our results will use the ip address for namespacing
|
||||||
|
|
|
@ -42,3 +42,19 @@ if Sidekiq.server?
|
||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq.logger.level = Logger::WARN
|
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
|
class SilenceLogger < Rails::Rack::Logger
|
||||||
|
PATH_INFO = 'PATH_INFO'.freeze
|
||||||
|
HTTP_X_SILENCE_LOGGER = 'HTTP_X_SILENCE_LOGGER'.freeze
|
||||||
|
|
||||||
def initialize(app, opts = {})
|
def initialize(app, opts = {})
|
||||||
@app = app
|
@app = app
|
||||||
@opts = opts
|
@opts = opts
|
||||||
|
@ -10,11 +13,13 @@ class SilenceLogger < Rails::Rack::Logger
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
prev_level = Rails.logger.level
|
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
|
Rails.logger.level = Logger::WARN
|
||||||
result = @app.call(env)
|
@app.call(env)
|
||||||
result
|
|
||||||
else
|
else
|
||||||
super(env)
|
super(env)
|
||||||
end
|
end
|
||||||
|
@ -23,5 +28,10 @@ class SilenceLogger < Rails::Rack::Logger
|
||||||
end
|
end
|
||||||
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
|
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
|
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"
|
get "site" => "site#index"
|
||||||
|
|
||||||
resources :forums
|
resources :forums
|
||||||
|
|
Loading…
Reference in a new issue