Skip to content

Switch to structured logging

Jacob Vosmaer requested to merge structured-logging into master

Part of #124 (closed)

This changes the log format to resemble that of logrus. The default format is text, with an option to output json logs instead.

In the examples below the first line comes from Go, the second two come from Ruby. I tried to make them similar in format, particularly in the JSON case.

Text format:

time="2018-03-15T11:36:17+01:00" level=error msg="unmarshaling request json failed" error="invalid character 'x' looking for beginning of value" pid=35481
time="2018-03-15T11:35:48+01:00" level=info msg="finished HTTP request" duration=1.157818 method=POST pid=35460 url="http+unix://gitlab.socket/api/v4/internal/allowed"
time="2018-03-15T11:35:48+01:00" level=warn msg="Access denied" command="git-upload-pack '/gitlab-org/gitlab-shell.git'" pid=35460 user="user with key key-1"

JSON format:

{"error":"invalid character 'x' looking for beginning of value","level":"error","msg":"unmarshaling request json failed","pid":21632,"time":"2018-03-14T11:08:07+01:00"}
{"method":"POST","url":"http+unix://gitlab.socket/api/v4/internal/allowed","duration":0.071899,"pid":21643,"level":"info","msg":"finished HTTP request","time":"2018-03-14T11:08:11+01:00"}
{"command":"git-upload-pack '/gitlab-org/gitlab-shell.git'","user":"user with key key-1","pid":21643,"level":"warn","msg":"Access denied","time":"2018-03-14T11:08:11+01:00"}

Because this breaks existing gitlab-shell log parsers I incremented the major version number.

Edited by Jacob Vosmaer

Merge request reports