Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Allow logging with json formatter

Oliver Günther3f0cf60d0681
diff --git a/config/initializers/grape_logging.rb b/config/initializers/grape_logging.rb
index 24ea3fd324c..6d28e965ec2 100644
--- a/config/initializers/grape_logging.rb
+++ b/config/initializers/grape_logging.rb
@@ -1,6 +1,6 @@
OpenProject::Application.configure do
config.after_initialize do
- formatter = ::Lograge::Formatters::KeyValue.new
+ formatter = OpenProject::Logging::Lograge.formatter_class.new
ActiveSupport::Notifications.subscribe('openproject_grape_logger') do |_, _, _, _, payload|
time = payload.delete :time
diff --git a/config/initializers/lograge.rb b/config/initializers/lograge.rb
index 474e20e90cd..6e8cf1dcbef 100644
--- a/config/initializers/lograge.rb
+++ b/config/initializers/lograge.rb
@@ -1,5 +1,8 @@
Rails.application.configure do
- config.lograge.enabled = Rails.env.production? || ENV['OPENPROJECT_LOGRAGE_ENABLED']
+ next unless OpenProject::Logging::Lograge.enabled?
+
+ config.lograge.enabled = true
+ config.lograge.formatter = OpenProject::Logging::Lograge.formatter_class.new
config.lograge.base_controller_class = %w[ActionController::Base]
# Add custom data to event payload
diff --git a/lib/open_project/configuration.rb b/lib/open_project/configuration.rb
index dcd28c45b11..fa7542a7d6e 100644
--- a/lib/open_project/configuration.rb
+++ b/lib/open_project/configuration.rb
@@ -204,7 +204,10 @@ module OpenProject
'ldap_groups_disable_sync_job' => false,
# Slow query logging threshold in ms
- 'sql_slow_query_threshold' => 2000
+ 'sql_slow_query_threshold' => 2000,
+
+ # Use lograge to format logs, off by default
+ 'lograge_formatter' => nil
}
@config = nil
diff --git a/lib/open_project/logging/lograge.rb b/lib/open_project/logging/lograge.rb
new file mode 100644
index 00000000000..3297f649436
--- /dev/null
+++ b/lib/open_project/logging/lograge.rb
@@ -0,0 +1,15 @@
+module OpenProject
+ module Logging
+ module Lograge
+ def self.enabled?
+ OpenProject::Configuration.lograge_formatter.present?
+ end
+
+ def self.formatter_class
+ formatter_setting = OpenProject::Configuration.lograge_formatter || 'key_value'
+
+ "Lograge::Formatters::#{formatter_setting.classify}".constantize
+ end
+ end
+ end
+end