GitLab Log基本使用方法

分享于 

8分钟阅读

git

  繁體

在服务器控制台tail log

如果想用'tail'实时查看GitLab日志更新,你可以使用gitlab-ctl tail


# Tail all logs; press Ctrl-C to exit
sudogitlab-ctl tail

# Drill down to a sub-directory of /var/log/gitlab
sudogitlab-ctl tailgitlab-rails

# Drill down to an individual file
sudogitlab-ctl tailnginx/gitlab_error.log

配置默认日志目录

/etc/gitlab/gitlab.rb文件中,对于不同类型的日志,有许多log_directory,取消注释,并且更新日志位置的值:


# For example:
gitlab_rails['log_directory'] = "/var/log/gitlab/gitlab-rails"
unicorn['log_directory'] = "/var/log/gitlab/unicorn"
registry['log_directory'] = "/var/log/gitlab/registry"
...

运行sudo gitlab-ctl reconfigure以使用这些设置配置实例。

runit日志

Omnibus GitLab中runit管理的服务使用svlogd生成日志数据。

你可以使用以下设置svlogd/etc/gitlab/gitlab.rb


# Below are the default values
logging['svlogd_size'] = 200 * 1024 * 1024 # rotate after 200 MB of log data
logging['svlogd_num'] = 30 # keep 30 rotated log files
logging['svlogd_timeout'] = 24 * 60 * 60 # rotate after 24 hours
logging['svlogd_filter'] = "gzip" # compress logs with gzip
logging['svlogd_udp'] = nil # transmit log messages via UDP
logging['svlogd_prefix'] = nil # custom prefix for log messages

# Optionally, you can override the prefix for e.g. Nginx
nginx['svlogd_prefix'] = "nginx"

回滚

从Omnibus GitLab 7.4开始Omnibus GitLab有alogrotate服务,此服务将回滚,压缩并最终删除runit的日志数据,例如gitlab-rails/production.lognginx/gitlab_access.log,可以通过/etc/gitlab/gitlab.rb配置logrotate。


# Below are some of the default settings
logging['logrotate_frequency'] = "daily" # rotate logs daily
logging['logrotate_maxsize'] = nil # logs will be rotated when they grow bigger than size spec如果ied for `maxsize`, even before the spec如果ied time interval (daily, weekly, monthly, or yearly)
logging['logrotate_size'] = nil # do not rotate by size by default
logging['logrotate_rotate'] = 30 # keep 30 rotated logs
logging['logrotate_compress'] = "compress" # see 'man logrotate'
logging['logrotate_method'] = "copytruncate" # see 'man logrotate'
logging['logrotate_postrotate'] = nil # no postrotate command by default
logging['logrotate_dateformat'] = nil # use date extensions for rotated files rather than numbers e.g. a value of "-%Y-%m-%d" would give rotated files like production.log-2016-03-09.gz


# You can add overrides per service
nginx['logrotate_frequency'] = nil
nginx['logrotate_size'] = "200M"

# You can also disable the built-in logrotate service 如果 you want
logrotate['enable'] = false

手动运行logrotate

Logrotate是计划的作业,但也可以按需触发。

要使用GitLab日志旋转手动触发logrotate,请使用以下命令:


/opt/gitlab/embedded/sbin/logrotate -fv /var/opt/gitlab/logrotate/logrotate.d -s /var/opt/gitlab/logrotate/logrotate.conf

UDP日志转发

如果你的中央服务器收集了所有基础设施日志,则可以配置Omnibus GitLab,通过UDP发送syslog ish日志消息:


logging['udp_log_shipping_host'] = '1.2.3.4' # Your syslog server
logging['udp_log_shipping_port'] = 1514 # Optional, defaults to 514 (syslog)

示例日志消息:


Jun 26 06:33:46 ubuntu1204-test production.log: Started GET "/root/my-project/import" for 127.0.0.1 at 2014-06-26 06:33:46 -0700
Jun 26 06:33:46 ubuntu1204-test production.log: Processing by ProjectsController#import as HTML
Jun 26 06:33:46 ubuntu1204-test production.log: Parameters: {"id"=>"root/my-project"}
Jun 26 06:33:46 ubuntu1204-test production.log: Completed 200 OK in 122ms (Views: 71.9ms | ActiveRecord: 12.2ms)
Jun 26 06:33:46 ubuntu1204-test gitlab_access.log: 172.16.228.1 - - [26/Jun/2014:06:33:46 -0700] "GET /root/my-project/import HTTP/1.1" 200 5775 "https://172.16.228.169/root/my-project/import" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"
2014-06-26_13:33:46.49866 ubuntu1204-test sidekiq: 2014-06-26T13:33:46Z 18107 TID-7nbj0 Sidekiq::Extensions::DelayedMailer JID-bbfb118dd1db20f6c39f5b50 INFO: start
2014-06-26_13:33:46.52608 ubuntu1204-test sidekiq: 2014-06-26T13:33:46Z 18107 TID-7muoc RepositoryImportWorker JID-57ee926c3655fcfa062338ae INFO: start

使用自定义Nginx日志格式

默认情况下,Nginx访问日志使用'combined' Nginx格式的版本,隐藏查询字符串中嵌入的潜在敏感信息,如果要使用自定义日志格式字符串,可以在/etc/gitlab/gitlab.rb中指定它有关格式的详细信息,请参见Nginx文档


nginx['log_format'] = 'my format string $foo $bar'
mattermost_nginx['log_format'] = 'my format string $foo $bar'

JSON日志记录

结构化日志可以通过JSON导出,由Elasticsearch.Splunk或其他日志管理系统解析,一些组件默认已经编写了JSON日志(例如,请参见gitLab CE日志记录文档),但是直到GitLab 12.0,有些GitLab组件可能还在使用非结构化格式,要在GitLab之前的版本中为所有组件启用JSON日志记录,请添加这些行,并运行gitlab-ctl reconfigure


gitaly['logging_format'] = 'json'
gitlab_shell['log_format'] = 'json'
gitlab_workhorse['log_format'] = 'json'
registry['log_formatter'] = 'json'
sidekiq['log_format'] = 'json'
gitlab_pages['log_format'] = 'json'

注意如果没有外部插件,PostgreSQL不支持JSON日志记录。但是,它支持以CSV格式记录日志:

postgresql['log_destination'] = 'csvlog'
postgresql['logging_collector'] = 'on'

重新启动数据库才能生效,有关详细信息,请参阅PostgreSQL文档

文本日志记录

旧行为可以通过在/etc/gitlab/gitlab.rb中设置以下内容,然后在以后运行gitlab-ctl reconfigure来保留:


gitaly['logging_format'] = 'default'
gitlab_shell['log_format'] = nil
gitlab_workhorse['log_format'] = nil
registry['log_formatter'] = 'text'
sidekiq['log_format'] = 'default'
gitlab_pages['log_format'] = 'text'


BASE  GIT  log  logs  Gitlab  
相关文章