Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

How to View and Manage System Logs Using journalctl in Linux

Published

troubleshooting

If you’ve ever found yourself staring at a Linux server wondering “what the heck just happened?”, you’re not alone. We’ve all been there – something breaks, users complain, and you need answers fast. That’s where good log management comes in, and frankly, it can make or break your day as a system administrator.

Most modern Linux distributions have moved to systemd, and with it comes a pretty neat logging system called the journal. Now, I know what you’re thinking – “great, another thing to learn.” But here’s the thing: unlike those old-school plain-text logs scattered all over your system, the journal keeps everything organized in one place using a structured binary format. It’s actually quite clever once you get used to it.

The tool that makes all this magic happen is journalctl. Think of it as your Swiss Army knife for logs – whether you’re hunting down why a service crashed at 3 AM, investigating suspicious activity, or just keeping an eye on things in real-time, this command has got your back.

I’m going to walk you through everything you need to know about journalctl, from the basics to some pretty useful advanced tricks. By the end of this, you’ll be navigating system logs like a pro.

Understanding journalctl

So what exactly is journalctl? Simply put, it’s your gateway to the systemd journal – that centralized logging system I mentioned earlier. Instead of having to remember where Apache logs live versus where kernel messages go, everything gets funneled into one place.

The binary format might sound intimidating, but it’s actually a huge advantage. You can slice and dice your logs in ways that would make traditional text-based log parsing look like child’s play. Plus, it’s fast – really fast.

Here’s why I think journalctl is worth your time:

Real-time monitoring: Ever used tail -f on a log file? This is like that, but better. You can watch logs stream by as they happen, which is incredibly useful when you’re troubleshooting live issues.

Smart filtering: This is where things get interesting. You can filter by service, time range, log level, or even specific processes. No more grepping through massive files hoping to find that one error message.

Persistent storage: Configure it right, and your logs will survive reboots. This has saved me more times than I can count when tracking down intermittent issues.

Everything in one place: Kernel messages, service logs, user activity – it’s all there. No more hopping between /var/log/messages, /var/log/syslog, and a dozen other files.

Basic Command Structure

The beauty of journalctl lies in its straightforward syntax:

journalctl [options]

Don’t worry about memorizing every option right away. These are the ones you’ll use most often:

  • -u when you want logs from a specific service
  • -p for filtering by how serious the message is
  • --since and --until for time-based filtering
  • -f for that real-time streaming I mentioned
  • --no-pager when you don’t want the output to pause every screen

Let’s jump into some real examples that you can actually use.

Viewing All System Logs

Want to see everything that’s been happening? Just run:

journalctl

This shows you logs from the current boot, with the newest stuff at the top. Fair warning though – on a busy system, this can be overwhelming. You’ll probably want to filter it down pretty quickly.

Focusing on Specific Services

Here’s where journalctl really shines. Instead of hunting through multiple log files, you can zero in on exactly what you need:

journalctl -u <service_name>

Let’s say your Apache server is acting up. Instead of digging through /var/log/apache2/, you can just run:

journalctl -u apache2

If you’re dealing with a service that’s been restarted and you want to see everything without pagination getting in the way:

journalctl -u apache2 --no-pager

This is especially handy when you’re piping output to other commands or just want to scroll through everything at your own pace.

Time-Based Filtering

One of my favorite features is how flexible the time filtering is. You don’t need to remember exact timestamp formats – journalctl understands human-friendly time descriptions.

To see what’s happened today:

journalctl --since today

Been away for the weekend and want to see what you missed?

journalctl --since "2 days ago"

Need to investigate something that happened during a specific window? You can get really precise:

journalctl --since "2025-04-01 00:00:00" --until "2025-04-02 00:00:00"

This kind of flexibility is a game-changer when you’re trying to correlate events across different timeframes.

Real-Time Monitoring

When you’re troubleshooting active issues, real-time monitoring is invaluable. The -f flag works just like tail -f, but with all the power of journalctl’s filtering:

journalctl -u apache2 -f

I use this constantly when I’m testing configuration changes or deploying new code. You can watch the logs scroll by and immediately see if something breaks. When you’re done watching, just hit Ctrl + C to stop.

Filtering by Log Priority

Not all log messages are created equal. Sometimes you just want to see the serious stuff and ignore the informational chatter. That’s where priority filtering comes in handy.

The priority levels follow the standard syslog convention:

  • emerg (0) – Your system is basically dead
  • alert (1) – Something needs immediate attention
  • crit (2) – Critical problems
  • err (3) – Regular errors
  • warning (4) – Warnings (something might be wrong)
  • notice (5) – Normal but noteworthy events
  • info (6) – General information
  • debug (7) – Detailed debugging info

To see only error-level messages and above:

journalctl -p err

You can also use numbers if you prefer:

journalctl -p 4

This shows warnings and anything more serious. It’s a great way to cut through the noise when you’re hunting for problems.

Viewing Previous Boot Logs

Here’s something that has saved me countless times: the ability to look at logs from previous boots. System crashed and rebooted? No problem – the evidence is still there.

To see logs from the last boot:

journalctl -b -1

You can go back further with -b -2, -b -3, and so on. This is incredibly useful for tracking down issues that only show up during startup or shutdown.

Exporting Logs for Analysis

Sometimes you need to save logs for deeper analysis or to share with colleagues. Redirection works exactly as you’d expect:

journalctl -u apache2 --no-pager > apache2_logs.txt

You can combine this with time filtering to export specific periods:

journalctl --since "2025-04-01" --until "2025-04-02" > april_logs.txt

This is particularly useful when you’re building incident reports or need to analyze patterns over time.

Monitoring Storage Usage

Logs can grow surprisingly quickly, especially on busy systems. It’s worth checking how much space they’re using:

journalctl --disk-usage

I make this part of my regular system monitoring routine. It’s better to catch log growth early than to deal with a full disk at 2 AM.

Log Management and Cleanup

When logs start taking up too much space, you have a few options for cleanup. You can limit the total size:

journalctl --vacuum-size=1G

Or remove logs older than a certain age:

journalctl --vacuum-time=7d

For long-term management, you’ll want to configure the journal settings in /etc/systemd/journald.conf, but these commands are great for immediate cleanup.

Best Practices and Tips

After years of working with journalctl, here are some tips that might save you some headaches:

Don’t try to drink from the fire hose. Always use filters to narrow down what you’re looking at. The -u, -p, and --since options are your friends.

Make real-time monitoring part of your workflow. The -f option is incredibly useful during deployments, configuration changes, or when you’re trying to reproduce issues.

Clean up regularly. Set up a routine for log cleanup using the vacuum options. Your future self (and your disk space) will thank you.

Export important logs. When you find something interesting or concerning, save it. You never know when you’ll need to reference it later or share it with someone else.

Conclusion

Mastering journalctl transforms log management from a frustrating task into an efficient process. This powerful tool provides centralized access to system logs with advanced filtering capabilities that significantly simplify troubleshooting and system monitoring.

Start with basic commands and gradually incorporate the advanced features into your workflow. Regular practice with time-based filtering, service-specific queries, and real-time monitoring will make you proficient in system log analysis. Remember to implement proper log cleanup routines to maintain optimal system performance.

Related guides

Account services are unavailable until the production backend is configured.