Configuring and Managing Logs in GitLab
GitLab leverages an effective logging system to monitor and record operational activities. Below outlines the configuration and management of log files in the GitLab environment.
Summary of Log Files
GitLab organizes its logs into several categories, each located within specific directories:
-
production.log: Documented under/home/gitlab/logs/gitlab-rails, this file captures detailed request information including URL, IP address, request type, associated code segments, SQL queries, and execution times. -
application.log: Found at/home/gitlab/logs/gitlab-rails, this log encompasses events like user creation and project modifications. -
githost.log: Situated in/home/gitlab/logs/gitlab-rails, it records errrors encountered on the server. -
sidekiq.log: Located under/home/gitlab/logs/gitlab-rails, this is designated for long-lived background tasks procesed by Sidekiq. -
gitlab-shell.log: Available in/home/gitlab/logs/gitlab-shell, this log pertains to GitLab command executions and SSH permisssion additions. -
unicorn.stderr.log: Found at/home/gitlab/logs/unicorn, it documents GitLab's web server operations. -
repocheck.log: Stored in/home/gitlab/logs/prometheus, this file is used for repository-related metrics.
Real-Time Log Viewing
Logs can be accessed using the gitlab-ctl tail command:
# Observe all logs in real-time
sudo gitlab-ctl tail
# Access specific logs under a directory
sudo gitlab-ctl tail gitlab-rails
# Tail a specific log file
sudo gitlab-ctl tail nginx/gitlab_error.log
Using Runit to Manage Logs
GitLab employs Runit for service management, leveraging svlogd to manage log files efficiently.
Modification of related setttings is achievable through updating /etc/gitlab/gitlab.rb:
logging['svlogd_size'] = 200 * 1024 * 1024 # Defines log file size
logging['svlogd_num'] = 30 # Retains logs for the specified days
logging['svlogd_timeout'] = 24 * 60 * 60 # Generates daily log files
logging['svlogd_filter'] = 'gzip' # Applies compression
logging['svlogd_udp'] = nil # UDP protocol configuration
logging['svlogd_prefix'] = 'application' # Prefix customization
Logrotate Configuration
To manage the size and retention of certain log files, GitLab includes the logrotate service. To customize its operation, modify /etc/gitlab/gitlab.rb:
logging['logrotate_frequency'] = 'daily' # Frequency of log rotation
logging['logrotate_rotate'] = 30 # Number of days for retention
logging['logrotate_compress'] = 'compress' # File compression behavior
logging['logrotate_method'] = 'copytruncate' # Rotation method
logrotate['enable'] = true # Enable or disable logrotate
UPS Protocol Log Export (Enterprise Edition)
GitLab Enterprise Edition facilitates log transmission over UDP. This configuration can be defined in /etc/gitlab/gitlab.rb:
logging['udp_log_shipping_host'] = '1.2.3.4' # Syslog server IP
logging['udp_log_shipping_port'] = 514 # Destination port
Customizing Nginx Logging Format
To adjust the format used within the NGINX access logs, change the following parameters inside /etc/gitlab/gitlab.rb:
nginx['log_format'] = 'custom format: $remote_addr $request_uri'
Configurations provided above allow for tailored logging behavior within GitLab environment.