mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 06:42:32 -05:00
add json log formatter
This commit is contained in:
1 parent
6736d8fe68
commit
14c0ad2d16
2 files changed
+26
-2
No files matched your search
@@ -103,7 +103,22 @@ Rails.application.configure do
|
||||
config.active_support.report_deprecations = false
|
||||
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||
config.log_formatter = Logger::Formatter.new
|
||||
json_formatter = Logger::Formatter.new
|
||||
json_formatter.define_singleton_method(:call) do |severity, time, _progname, msg|
|
||||
data = { ts: time.utc.iso8601(3), pid: Process.pid, lvl: severity }
|
||||
data[:tags] = current_tags.join(',') if current_tags.any?
|
||||
|
||||
if msg.is_a?(Hash)
|
||||
data.merge!(msg)
|
||||
else
|
||||
data[:msg] = msg2str(msg)
|
||||
end
|
||||
|
||||
"#{data.to_json}\n"
|
||||
end
|
||||
json_formatter.define_singleton_method(:tags_text) { '' }
|
||||
|
||||
config.log_formatter = ENV['LOG_FORMATTER'] == 'json' ? json_formatter : Logger::Formatter.new
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# require "syslog/logger"
|
||||
@@ -129,7 +144,12 @@ Rails.application.configure do
|
||||
config.lograge.enabled = true
|
||||
config.lograge.base_controller_class = ['ActionController::API', 'ActionController::Base']
|
||||
|
||||
config.lograge.formatter = ->(data) { data.except(:path, :location).to_json }
|
||||
config.lograge.formatter =
|
||||
if ENV['LOG_FORMATTER'] == 'json'
|
||||
->(data) { data.except(:path, :location) }
|
||||
else
|
||||
->(data) { data.except(:path, :location).to_json }
|
||||
end
|
||||
|
||||
config.lograge.custom_payload do |controller|
|
||||
params =
|
||||
|
||||
@@ -12,3 +12,7 @@ if !ENV['SIDEKIQ_BASIC_AUTH_PASSWORD'].to_s.empty? && defined?(Sidekiq::Web)
|
||||
end
|
||||
|
||||
Sidekiq.strict_args!
|
||||
|
||||
Sidekiq.configure_server do |config|
|
||||
config.logger.formatter = Sidekiq::Logger::Formatters::JSON.new if ENV['LOG_FORMATTER'] == 'json'
|
||||
end
|
||||
Reference in new issue
Block a user