summaryrefslogtreecommitdiff
path: root/app/models/concerns/integrations/loggable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/integrations/loggable.rb')
-rw-r--r--app/models/concerns/integrations/loggable.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/concerns/integrations/loggable.rb b/app/models/concerns/integrations/loggable.rb
new file mode 100644
index 00000000000..57847ea335c
--- /dev/null
+++ b/app/models/concerns/integrations/loggable.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Integrations
+ module Loggable
+ def log_info(message, params = {})
+ message = build_message(message, params)
+
+ logger.info(message)
+ end
+
+ def log_error(message, params = {})
+ message = build_message(message, params)
+
+ logger.error(message)
+ end
+
+ def log_exception(error, params = {})
+ Gitlab::ExceptionLogFormatter.format!(error, params)
+
+ log_error(params[:message] || error.message, params)
+ end
+
+ def build_message(message, params = {})
+ {
+ integration_class: self.class.name,
+ integration_id: id,
+ project_id: project&.id,
+ project_path: project&.full_path,
+ message: message
+ }.merge(params)
+ end
+
+ def logger
+ Gitlab::IntegrationsLogger
+ end
+ end
+end