MC, 2023
Ilustracja do artykułu: Logs of a specific service in Linux

Logs of a specific service in Linux

In this note, I show you how to read the logs of a specific serivce running on Linux.

Where are the logs?

I recently had such a problem that an application written in .NET Core running as a service did not get up. Why? Well, that's what I was trying to find out. The status of the service was "activating", and nothing appeared in the application's logs - so it means that the problem appeared at an early stage of its life.

The most sensible solution is to get to the service logs kept at the system level. But how to do it?

The journalctl command comes in handy with the -u --unit=UNIT switch, after which we can indicate the name of the unit we are interested in, in this case the service.

$ journalctl -u name-of-the.service

At the same time, it is worth noting that we will probably be flooded with a stream of logs. So if you, like me, need to investigate a recent issue, there are two best things you can do to narrow down the scope of your logs. The first is the -b switch, which allows you to return logs from a running login session. If that's still too much, I recommend appending the tail command pim, which will limit the results to the last n lines (100 in the example below).

$ journalctl -u name-of-the.service -b | tail -n 100

Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!

Imię:
Treść:
Polish version: Logi konkretnego serwisu w Linux