Understanding Ubuntu Log Levels
Log levels define the severity of logged events, helping administrators filter and prioritize system/app messages. Ubuntu supports standard log levels (from most severe to least): emerg (system unusable), alert (immediate action required), crit (critical errors), err (errors), warning (potential issues), notice (normal but important), info (general information), and debug (detailed debugging). Choosing the right level balances log detail and storage usage—for example, debug is useful for troubleshooting but can clutter logs in production.
1. Configuring rsyslog (Default System Log Service)
rsyslog is Ubuntu’s default logging service. To adjust log levels:
/etc/rsyslog.conf with a text editor (e.g., sudo nano /etc/rsyslog.conf).#kern.* /dev/console (comments are disabled by default). Change the level (e.g., kern.* /var/log/kern.log to log all kernel messages, or kern.err /var/log/kern.log to log only kernel errors).sudo systemctl restart rsyslog./etc/rsyslog.d/ (e.g., 50-default.conf)—this is recommended for customizing specific services (e.g., Apache, Nginx).2. Configuring systemd-journald (Systemd Log Manager)
systemd-journald manages logs for systemd-based systems. To set log levels:
/etc/systemd/journald.conf with sudo nano.SystemMaxLevel (for persistent logs) and RuntimeMaxLevel (for volatile logs, stored in RAM). For example, set both to debug to capture detailed logs:SystemMaxLevel=debug
RuntimeMaxLevel=debug
sudo systemctl restart systemd-journald.3. Application-Specific Log Level Settings
Many applications (e.g., Apache, Nginx) have their own log level configurations. These settings override system-wide defaults:
/etc/apache2/apache2.conf or a virtual host file in /etc/apache2/sites-available/). Modify the LogLevel directive (e.g., LogLevel debug to enable debug logs). Restart Apache with sudo systemctl restart apache2./etc/nginx/nginx.conf). Modify the error_log directive (e.g., error_log /var/log/nginx/error.log debug; to enable debug logs). Restart Nginx with sudo systemctl restart nginx.4. Key Considerations for Log Level Management
debug) generate large volumes of logs, which can fill disk space. Use tools like logrotate (configured in /etc/logrotate.conf) to automate log rotation, compression, and retention.debug mode in production—it may expose sensitive information (e.g., passwords, API keys) in logs.5. Verifying Log Levels
To confirm current log levels:
/etc/rsyslog.conf) or view logs with journalctl -u rsyslog.journalctl --disk-usage (indirectly) or check /etc/systemd/journald.conf.LogLevel, Nginx’s error_log) or documentation.