Convert githost.log to JSON format

This will make it easier to parse this in production and adds the
`correlation_id` if available.
This commit is contained in:
Stan Hu 2019-07-19 15:17:54 -07:00 committed by Mayra Cabrera
parent 0e6c76a7bb
commit 71045b89f6
3 changed files with 16 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
title: Convert githost.log to JSON format
merge_request: 30967
author:
type: changed

View file

@ -157,16 +157,22 @@ This file lives in `/var/log/gitlab/gitlab-rails/githost.log` for
Omnibus GitLab packages or in `/home/git/gitlab/log/githost.log` for
installations from source.
NOTE: **Note:**
After 12.2, this file will be stored in JSON format.
GitLab has to interact with Git repositories but in some rare cases
something can go wrong and in this case you will know what exactly
happened. This log file contains all failed requests from GitLab to Git
repositories. In the majority of cases this file will be useful for developers
only. For example:
```
December 03, 2014 13:20 -> ERROR -> Command failed [1]: /usr/bin/git --git-dir=/Users/vsizov/gitlab-development-kit/gitlab/tmp/tests/gitlab-satellites/group184/gitlabhq/.git --work-tree=/Users/vsizov/gitlab-development-kit/gitlab/tmp/tests/gitlab-satellites/group184/gitlabhq merge --no-ff -mMerge branch 'feature_conflict' into 'feature' source/feature_conflict
error: failed to push some refs to '/Users/vsizov/gitlab-development-kit/repositories/gitlabhq/gitlab_git.git'
```json
{
"severity":"ERROR",
"time":"2019-07-19T22:16:12.528Z",
"correlation_id":"FeGxww5Hj64",
"message":"Command failed [1]: /usr/bin/git --git-dir=/Users/vsizov/gitlab-development-kit/gitlab/tmp/tests/gitlab-satellites/group184/gitlabhq/.git --work-tree=/Users/vsizov/gitlab-development-kit/gitlab/tmp/tests/gitlab-satellites/group184/gitlabhq merge --no-ff -mMerge branch 'feature_conflict' into 'feature' source/feature_conflict\n\nerror: failed to push some refs to '/Users/vsizov/gitlab-development-kit/repositories/gitlabhq/gitlab_git.git'"
}
```
## `audit_json.log`

View file

@ -1,13 +1,9 @@
# frozen_string_literal: true
module Gitlab
class GitLogger < Gitlab::Logger
class GitLogger < JsonLogger
def self.file_name_noext
'githost'
end
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_s(:long)} -> #{severity} -> #{msg}\n"
end
end
end