Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
5665ecee
Commit
5665ecee
authored
Mar 02, 2019
by
Steve Azzopardi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logging info to Go guide
closes
https://gitlab.com/gitlab-org/gitlab-ce/issues/57298
parent
e4b2c3b0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
doc/development/go_guide/index.md
doc/development/go_guide/index.md
+30
-3
No files found.
doc/development/go_guide/index.md
View file @
5665ecee
...
...
@@ -161,12 +161,39 @@ in the code.
### Logging
The usage of a logging library is strongly recommended for daemons. Even
though
there is a
`log`
package in the standard library, we generally use
[
l
ogrus
](
https://github.com/sirupsen/logrus
)
. Its plugin ("hooks") system
The usage of a logging library is strongly recommended for daemons. Even
th
ough th
ere is a
`log`
package in the standard library, we generally use
[
L
ogrus
](
https://github.com/sirupsen/logrus
)
. Its plugin ("hooks") system
makes it a powerful logging library, with the ability to add notifiers and
formatters at the logger level directly.
#### Structured (JSON) logging
Every binary ideally must have structured (JSON) logging in place as it helps
with searching and filtering the logs. At GitLab we use structured logging in
JSON format, as all our infrastructure assumes that. When using
[
Logrus
](
https://github.com/sirupsen/logrus
)
you can turn on structured
logging simply by using the build in
[
JSON
formatter
](
https://github.com/sirupsen/logrus#formatters
)
. This follows the
same logging type we use in our
[
Ruby
applications
](
../logging.md#use-structured-json-logging
)
.
#### How to use Logrus
There are a few guidelines one should follow when using the
[
Logrus
](
https://github.com/sirupsen/logrus
)
package:
-
When printing an error use
[
WithError
](
https://godoc.org/github.com/sirupsen/logrus#WithError
)
. For
exmaple,
`logrus.WithError(err).Error("Failed to do something")`
.
-
Since we use
[
structured logging
](
#structured-json-logging
)
we can log
fields in the context of that code path, such as the URI of the request using
[
`WithField`
](
https://godoc.org/github.com/sirupsen/logrus#WithField
)
or
[
`WithFields`
](
https://godoc.org/github.com/sirupsen/logrus#WithFields
)
. For
example,
`logrus.WithField("file", "/app/go).Info("Opening dir")`
. If you
have to log multiple keys, always use
`WithFields`
instead of calling
`WithField`
more than once.
### Tracing and Correlation
[
LabKit
](
https://gitlab.com/gitlab-org/labkit
)
is a place to keep common
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment