0Pricing
Linux Command Line Mastery · Lesson

Centralized Logging and Rotation with journald and logrotate

Keep automated systems healthy by reading systemd logs with journalctl and preventing log files from filling disks using logrotate.

Centralized Logging and Rotation with journald and logrotate is a free Linux Command Line Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Automation Needs Logs

Cron jobs, systemd services, and shell functions all produce output. To run unattended systems you must capture, search, and rotate that output. Enter journalctl and logrotate.

What Is journald?

systemd-journald collects logs from services you manage with systemctl into a structured binary journal you query with journalctl.

Viewing Logs

Plain journalctl shows everything; -e jumps to the end (newest entries).

journalctl -e

Filtering by Service

-u limits the journal to one unit, perfect for debugging a single service.

journalctl -u nginx.service

Following Logs Live

-f streams new entries as they arrive, like tail -f for systemd.

journalctl -u nginx.service -f

Filtering by Time and Priority

--since and -p narrow results. Here we show errors from the last hour.

journalctl --since '1 hour ago' -p err

Controlling Journal Size

Journals can grow large. --vacuum-size trims them to a target size.

sudo journalctl --vacuum-size=200M

Plain-Text Logs and logrotate

Many apps still write to /var/log/*.log. logrotate rotates, compresses, and deletes these on a schedule so disks do not fill.

cat /etc/logrotate.conf

A logrotate Rule

Drop a config in /etc/logrotate.d/. This rotates daily, keeps 7 copies, and compresses old ones.

/var/log/myapp/*.log {
  daily
  rotate 7
  compress
  missingok
  notifempty
}

Testing logrotate

-d does a debug dry run that shows what would happen without changing files; -f forces an immediate rotation.

sudo logrotate -d /etc/logrotate.d/myapp

Tying It to Automation

Have cron jobs and functions log to a dedicated file, manage that file with a logrotate rule, and use journalctl for everything run as a systemd service. Now nothing fills the disk silently.

Quick Check

Which journalctl option shows logs for a single systemd service?

Recap

You can keep automated systems observable and tidy:

  • journalctl -u, -f, --since, -p query systemd logs
  • --vacuum-size trims the journal
  • logrotate rotates/compresses plain-text logs via /etc/logrotate.d/
  • logrotate -d dry-runs your config

Frequently asked questions

Is the “Centralized Logging and Rotation with journald and logrotate” lesson free?

Yes — the full text of “Centralized Logging and Rotation with journald and logrotate” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Centralized Logging and Rotation with journald and logrotate”?

Keep automated systems healthy by reading systemd logs with journalctl and preventing log files from filling disks using logrotate. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Command Line Mastery?

No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Centralized Logging and Rotation with journald and logrotate” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Command Line Mastery lesson?

Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Job Scheduling: `cron` and `at`
  2. Service Management: `systemctl` (systemd)
  3. Automating Tasks with Shell Functions
  4. Centralized Logging and Rotation with journald and logrotate
← Back to Linux Command Line Mastery