Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/logging.md')
-rw-r--r--doc/development/logging.md24
1 files changed, 23 insertions, 1 deletions
diff --git a/doc/development/logging.md b/doc/development/logging.md
index 538fc7ccfe1..6840445a0a5 100644
--- a/doc/development/logging.md
+++ b/doc/development/logging.md
@@ -4,7 +4,7 @@ group: Respond
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
---
-# GitLab Developers Guide to Logging
+# Logging development guidelines
[GitLab Logs](../administration/logs/index.md) play a critical role for both
administrators and GitLab team members to diagnose problems in the field.
@@ -169,6 +169,28 @@ Resources:
- [Elasticsearch mapping - avoiding type gotchas](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping.html#_avoiding_type_gotchas)
- [Elasticsearch mapping types]( https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html)
+#### Include a class attribute
+
+Structured logs should always include a `class` attribute to make all entries logged from a particular place in the code findable.
+To automatically add the `class` attribute, you can include the
+[`Gitlab::Loggable` module](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/loggable.rb) and use the `build_structured_payload` method.
+
+```ruby
+class MyClass
+ include ::Gitlab::Loggable
+
+ def my_method
+ logger.info(build_structured_payload(message: 'log message', project_id: project_id))
+ end
+
+ private
+
+ def logger
+ @logger ||= Gitlab::AppJsonLogger.build
+ end
+end
+```
+
#### Logging durations
Similar to timezones, choosing the right time unit to log can impose avoidable overhead. So, whenever