Fading Coder

An Old Coder’s Final Dance

You are here: Home > Tech > Content

Configuring and Managing Logs in GitLab

Tech 3

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:

  1. 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.

  2. application.log: Found at /home/gitlab/logs/gitlab-rails, this log encompasses events like user creation and project modifications.

  3. githost.log: Situated in /home/gitlab/logs/gitlab-rails, it records errrors encountered on the server.

  4. sidekiq.log: Located under /home/gitlab/logs/gitlab-rails, this is designated for long-lived background tasks procesed by Sidekiq.

  5. gitlab-shell.log: Available in /home/gitlab/logs/gitlab-shell, this log pertains to GitLab command executions and SSH permisssion additions.

  6. unicorn.stderr.log: Found at /home/gitlab/logs/unicorn, it documents GitLab's web server operations.

  7. 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.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.