Example journalctl commands
The basics of working with journalctl
are simple. Think about it; when you’re troubleshooting an application, what do you need to be able to do with its logs?
First, you’ll want to be able to find and view the current set of logs. journalctl
will give you that, but you’ll quickly realize you didn’t actually want all the logs, just the most recent ones. So, let’s filter with the -n
flag.
To get a look at the last 100 log messages in journald
, try this command:
journalctl –n 100
This will print out the last 100 lines logged to the system. You will notice that this is similar to the tail
command explained earlier in this book. If you followed along, these lines will likely contain the “Hello World!” message from above.
Following active logs for a unit
You might also want to see logs in real time. For example, following your application logs during startup can help you see exactly...