下载、克隆、拉取代码有日志记录怎么做日志记录?

下载、克隆、拉取代码有日志记录怎么做日志记录?

您指的是保存日志记录吗?

对,如果能在页面上显示那肯定更加友好。

如果你对ELK或EFK这类工具熟悉,可以将日志推送到这类日志专用工具里记录并展示。

您的意思是gitlab有下载、克隆、拉取代码有日志的日志文件生成?

有的, 分析用户pull/clonepush等行为,当使用http协议进行操作时日志会被记录到:/var/log/gitlab/gitlab-rails/production_json.log ,当使用ssh协议进行操作时日志会被记录到:/var/log/gitlab/gitlab-shell/gitlab-shell.log,日志示例如下:

{
    "method": "POST",
    "path": "/efk/logtest.git/git-upload-pack",
    "format": null,
    "controller": "Repositories::GitHttpController",
    "action": "git_upload_pack",
    "status": 200,
    "time": "2022-04-25T02:12:45.285Z",
    "params": [
        {
            "key": "repository_path",
            "value": "efk/logtest.git"
        }
    ],
    "correlation_id": "01G1F7W79M6XBXF1BVCMAJHJ4D",
    "meta.user": "root",
    "meta.project": "efk/logtest",
    "meta.root_namespace": "efk",
    "meta.client_id": "user/1",
    "meta.caller_id": "Repositories::GitHttpController#git_upload_pack",
    "meta.remote_ip": "171.212.137.70",
    "meta.feature_category": "source_code_management",
    "remote_ip": "171.212.137.70",
    "user_id": 1,
    "username": "root",
    ...
}
{
    "command": "git-receive-pack",
    "correlation_id": "01G1HZN4RFQEKJQEY8E44907N3",
    "git_protocol": "",
    "gl_key_id": 3,
    "gl_key_type": "key",
    "gl_project_path": "efk/logtest",
    "gl_repository": "project-76",
    "level": "info",
    "msg": "executing git command",
    "remote_ip": "218.88.12.31",
    "time": "2022-04-26T03:46:47Z",
    "user_id": "user-19",
    "username": "andydwyer"
}

日志中有详细记录用户、项目、仓库等内容。将日志推送到ELK或EFK后,再进行筛选展示。

好的,非常感谢。 :pray: