mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Redo DiscourseLogstashLogger to not rely on logstash-logger (#27759)
This reverts commit 92d7d24d0f.
This commit is contained in:
committed by
GitHub
parent
b46e1fe2aa
commit
28f5550886
@@ -44,6 +44,7 @@ Discourse::Application.configure do
|
||||
|
||||
config.log_level = ENV["DISCOURSE_DEV_LOG_LEVEL"] if ENV["DISCOURSE_DEV_LOG_LEVEL"]
|
||||
|
||||
config.active_record.logger = nil if ENV["RAILS_DISABLE_ACTIVERECORD_LOGS"] == "1"
|
||||
config.active_record.verbose_query_logs = true if ENV["RAILS_VERBOSE_QUERY_LOGS"] == "1"
|
||||
|
||||
if defined?(BetterErrors)
|
||||
@@ -90,8 +91,6 @@ Discourse::Application.configure do
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Base.logger = nil if ENV["RAILS_DISABLE_ACTIVERECORD_LOGS"] == "1"
|
||||
|
||||
if ENV["BULLET"]
|
||||
Bullet.enable = true
|
||||
Bullet.rails_logger = true
|
||||
|
||||
@@ -107,18 +107,29 @@ Rails.application.config.to_prepare do
|
||||
end
|
||||
end
|
||||
|
||||
if ENV["LOGSTASH_URI"]
|
||||
if ENV["ENABLE_LOGSTASH_LOGGER"] == "1"
|
||||
config.lograge.formatter = Lograge::Formatters::Logstash.new
|
||||
|
||||
require "discourse_logstash_logger"
|
||||
|
||||
config.lograge.logger =
|
||||
DiscourseLogstashLogger.logger(uri: ENV["LOGSTASH_URI"], type: :rails)
|
||||
DiscourseLogstashLogger.logger(
|
||||
logdev: Rails.root.join("log", "#{Rails.env}.log"),
|
||||
type: :rails,
|
||||
customize_event:
|
||||
lambda do |event|
|
||||
event["database"] = RailsMultisite::ConnectionManagement.current_db
|
||||
end,
|
||||
)
|
||||
|
||||
# Remove ActiveSupport::Logger from the chain and replace with Lograge's
|
||||
# logger
|
||||
Rails.logger.stop_broadcasting_to(Rails.logger.broadcasts.first)
|
||||
Rails.logger.broadcast_to(config.lograge.logger)
|
||||
# Stop broadcasting to Rails' default logger
|
||||
Rails.logger.stop_broadcasting_to(
|
||||
Rails.logger.broadcasts.find { |logger| logger.is_a?(ActiveSupport::Logger) },
|
||||
)
|
||||
|
||||
Logster.logger.subscribe do |severity, message, progname, opts, &block|
|
||||
config.lograge.logger.add_with_opts(severity, message, progname, opts, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
|
||||
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
||||
|
||||
if (ENV["LOGSTASH_UNICORN_URI"] || "").length > 0
|
||||
enable_logstash_logger = ENV["ENABLE_LOGSTASH_LOGGER"] == "1"
|
||||
unicorn_stderr_path = "#{discourse_path}/log/unicorn.stderr.log"
|
||||
unicorn_stdout_path = "#{discourse_path}/log/unicorn.stdout.log"
|
||||
|
||||
if enable_logstash_logger
|
||||
require_relative "../lib/discourse_logstash_logger"
|
||||
require_relative "../lib/unicorn_logstash_patch"
|
||||
logger DiscourseLogstashLogger.logger(uri: ENV["LOGSTASH_UNICORN_URI"], type: :unicorn)
|
||||
FileUtils.touch(unicorn_stderr_path) if !File.exist?(unicorn_stderr_path)
|
||||
logger DiscourseLogstashLogger.logger(logdev: unicorn_stderr_path, type: :unicorn)
|
||||
else
|
||||
logger Logger.new(STDOUT)
|
||||
end
|
||||
|
||||
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
||||
|
||||
# tune down if not enough ram
|
||||
worker_processes (ENV["UNICORN_WORKERS"] || 3).to_i
|
||||
|
||||
@@ -25,18 +31,18 @@ FileUtils.mkdir_p("#{discourse_path}/tmp/pids") if !File.exist?("#{discourse_pat
|
||||
# feel free to point this anywhere accessible on the filesystem
|
||||
pid(ENV["UNICORN_PID_PATH"] || "#{discourse_path}/tmp/pids/unicorn.pid")
|
||||
|
||||
if ENV["RAILS_ENV"] != "production"
|
||||
logger Logger.new(STDOUT)
|
||||
# we want a longer timeout in dev cause first request can be really slow
|
||||
timeout(ENV["UNICORN_TIMEOUT"] && ENV["UNICORN_TIMEOUT"].to_i || 60)
|
||||
else
|
||||
if ENV["RAILS_ENV"] == "production"
|
||||
# By default, the Unicorn logger will write to stderr.
|
||||
# Additionally, some applications/frameworks log to stderr or stdout,
|
||||
# so prevent them from going to /dev/null when daemonized here:
|
||||
stderr_path "#{discourse_path}/log/unicorn.stderr.log"
|
||||
stdout_path "#{discourse_path}/log/unicorn.stdout.log"
|
||||
stderr_path unicorn_stderr_path
|
||||
stdout_path unicorn_stdout_path
|
||||
|
||||
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
||||
timeout 30
|
||||
else
|
||||
# we want a longer timeout in dev cause first request can be really slow
|
||||
timeout(ENV["UNICORN_TIMEOUT"] && ENV["UNICORN_TIMEOUT"].to_i || 60)
|
||||
end
|
||||
|
||||
# important for Ruby 2.0
|
||||
|
||||
Reference in New Issue
Block a user