1088

I check service status with systemctl status service-name.

By default, I see few rows only, so I add -n50 to see more.

Sometimes, I want to see full log, from start. It could have 1000s of rows.
Now, I check it with -n10000 but that doesn't look like neat solution.

Is there an option to check full systemd service log similar to less command?

10robinho
  • 11,279

7 Answers7

1562

Just use the journalctl command, as in:

journalctl -u service-name.service

Or, to see only log messages for the current boot:

journalctl -u service-name.service -b

For things named <something>.service, you can actually just use <something>, as in:

journalctl -u service-name

But for other sorts of units (sockets, targets, timers, etc), you need to be explicit.

In the above commands, the -u flag is short for --unit, and specifies the name of the unit in which you're interested. -b is short for --boot, and restricts the output to only the current boot so that you don't see lots of older messages. See the journalctl man page for more information.

larsks
  • 39,014
  • 115
    appending --no-pager will print full log, so you wont have to scroll – Dushyant Bangal May 29 '17 at 11:41
  • 139
    appending -e will start the log at the end removing the need to scroll, but without printing the entire log beforehand. – timlyo Jul 28 '17 at 14:45
  • 172
    appending -f will follow (print) updates to the log – Joe Jasinski Sep 06 '17 at 17:10
  • 102
    appending --help will let you see all available options – Tzafrir Mar 26 '18 at 20:14
  • 2
    are these logs being stored somewhere on the disk? – viveksinghggits Apr 11 '19 at 10:09
  • @viveksinghggits generally, although it depends on your configuration, but you still need to use journalctl to access them. – larsks Apr 11 '19 at 11:43
  • got it @larsks. https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html – viveksinghggits Apr 11 '19 at 11:58
  • 12
    Actually, this was not helpful for me - I want only the output since the unit was (re)started. sudo systemctl -n 99999 status gives me that, but apparently journalctl can only filter "from boot", not "from service start". – tobixen Jun 26 '19 at 04:57
  • I assume --no-pager will allow it to be piped? (say, to grep?) – DarthCadeus Nov 07 '19 at 14:10
  • 2
    --no-pager is not necessary when piping the output. It's only useful to disable the pager when output is to an interactive terminal. journalctl does not use a pager when you're piping the output to something else. – larsks Nov 07 '19 at 14:12
  • You can combine/append multiple units (-u) and thus combine the log of multiple services. – rugk Jul 28 '20 at 12:32
  • 1
    You can use shift-g to jump to the end of file in less or similar pagers. – Matthias Sep 03 '20 at 22:14
  • 2
    Appending -o cat will remove systemd log text processing so you can see the output as the process produced it. – fuzzyTew Jun 30 '21 at 10:11
  • NB: do NOT use journalctl UNIT=foobar.service thinking like me that it's the same as journalctl -u foobar.service, because it's not! With UNIT= sudo commands coming from a custom script are not listed; they are displayed with -u. – 4wk_ Jan 19 '22 at 16:28
  • 1
    whatever options I choose, I get -- No entries -- – Alecz Sep 14 '22 at 17:18
  • 1
    I really don't know why the message that tells you to check journalctl for more information doesn't tell you to do this - you know, the thing that will actually check for more information. It's so insane. – kristopolous Jul 24 '23 at 01:21
86

systemctl can include the complete output of its status listing, without truncation., by adding the -l flag:

systemctl -l status service-name

-l: don't truncate entries with ellipses (...)

--no-pager can be added to avoid invoking a pager when the output is an interactive terminal.

erik258
  • 373
Julien
  • 1,049
  • 7
    Could you explicit your answer somehow? Adding some explanation about the options, and don't hesitate to format your answer! – joH1 Jan 24 '18 at 10:20
  • 42
    This answer is wrong. The output stays truncated. – phil294 Oct 30 '18 at 14:21
  • might not be best for current one, but gods... it will make my life easier going forward :D – Tom St Aug 14 '21 at 14:51
  • 1
    Since this no longer works on my system, I've posted another answer that makes it posible to get the full logs via systemctl (with full support to journalctl's options to boot). It's a hack but it's been working great for me so far. – Tenders McChiken Oct 17 '21 at 08:22
52

Use journalctl to View Your System's Logs

          ︙

View journalctl without Paging

To send your logs to standard output and avoid paging them, use the --no-pager option:

journalctl --no-pager

It’s not recommended that you do this without first filtering down the number of logs shown.

journalctl -u service-name.service

          ︙

Show Logs within a Time Range

Use the --since option to show logs after a specified date and time:

journalctl --since "2018-08-30 14:10:10"

Use the --until option to show logs up to a specified date and time:

journalctl --until "2018-09-02 12:05:50"

Combine these to show logs between the two times:

journalctl --since "2018-08-30 14:10:10" --until "2018-09-02 12:05:50"

The above was largely copied from Use journalctl to View Your System's Logs at Linode Docs.  There is more information available there.

champion-runner
  • 1,055
  • 11
  • 11
  • 2
    @RokeJulianLockhart: Please pay more attention to what you are doing.  PagingPermalink and RangePermalink are not code / command / keywords.  champion-runner blindly copied from the source document and somehow converted some non-textual links into the word “Permalink”.  Your edit nearly set his error in concrete. – G-Man Says 'Reinstate Monica' Mar 29 '24 at 20:08
  • In that case, apologies, @G-ManSays'ReinstateMonica'. However, what do those terms refer to, then? That's very unusual standard English, if it is so. – Roke Julian Lockhart Beedell Mar 30 '24 at 16:20
  • @RokeJulianLockhart: Apology accepted.   /    Look at the linked page and search for “To send your logs to standard output”.  It’s under a heading, “View journalctl without Paging  #”.  The “#” is a link to “https://www.linode.com/docs/guides/how-to-use-journalctl/#view-journalctl-without-paging”, i.e., a direct link to that section.  All the headings have direct links like that. – G-Man Says 'Reinstate Monica' Mar 30 '24 at 18:16
  • OK, “Permalink” is, obviously, short for “Permanent link”.  It’s a somewhat common web term.  For example, https://unix.stackexchange.com/a/552945 is a direct link to champion-runner’s answer, which we both edited.  It will take you to the (then) current state of the answer and its comments.  But https://unix.stackexchange.com/revisions/552945/1 is a permanent link to the first draft/revision of the answer — what it looked like before you edited it.  In other words, a link that is expected to work in the future to get to the exact same place it goes to today. … (Cont’d) – G-Man Says 'Reinstate Monica' Mar 30 '24 at 18:16
  • (Cont’d) …   Now, I don’t understand why linode.com uses the term “permalink” to refer to what I would call a “direct link”, but, apparently, they do.     /     So, to repeat what I said yesterday, champion-runner somehow copied “Paging  #” and pasted “PagingPermalink”. – G-Man Says 'Reinstate Monica' Mar 30 '24 at 18:16
  • "PagingPermalink" is not standard English, although if I codified "Permalink", that was an accident. Thanks for the elaboration. – Roke Julian Lockhart Beedell Mar 30 '24 at 22:42
51

Most of the time, it is convenient and easy to use the following bash command:

journalctl -xefu service-name.service

or

journalctl -xefu service-name

It works as if the process is executed via shell and the output is changing dynamically (similar to tail -f).

  • 2
    This is the only answer that shows if a unit has been started or stopped (or likewise restart). – Dave Mar 11 '22 at 14:19
17

Using journalctl, write logs to a text file, and read it bottom up:

journalctl -u service-name.service > file_name.txt &&\
tail file_name.txt
J11
  • 271
9

Since @Julien's answer no longer appears to work on my system (Debian 11), I've finally given in and hijacked systemctl on my system:

systemctl() { 
    if [[ "${1-}" == "log" ]]; then  
        /usr/bin/journalctl -u "${@:2}"; 
    else /usr/bin/systemctl "$@";
    fi 
}

Add this one-liner to your .bashrc and your systemctl will gain a new log "verb" that provides the missing functionality. No more wasting time retyping tedious commands.

As an added bonus, this method will also give you access to all the options of journalctl (provided that they're specified after the unit name):

systemctl log named.service --since=today

Edit: To address John's comment about the lack of bash-completion support and provide a more complete answer, we might as well hijack systemctl's bash completion function too:

source "/usr/share/bash-completion/completions/systemctl"
source "/usr/share/bash-completion/completions/journalctl"

_systemd_log_hijack() { if [[ "${COMP_WORDS[1]}" == "log" ]]; then if [[ "${COMP_CWORD}" == "2" ]]; then COMPREPLY=( $(systemctl list-units 2>&1 | awk -c ' { print $1 }' | grep -F "${COMP_WORDS[2]}") ) elif [[ "${COMP_CWORD}" -gt "2" ]]; then (( COMP_CWORD++ )) || true COMP_WORDS=("journalctl" "-u" "${COMP_WORDS[2]}" "${COMP_WORDS[@]:2}") COMP_LINE="${COMP_WORDS[*]}" _journalctl fi
else _systemctl fi

if [[ &quot;${COMP_CWORD}&quot; == &quot;1&quot; &amp;&amp; &quot;log&quot; == &quot;${COMP_WORDS[1]}&quot;* ]]; then
    COMPREPLY=(&quot;log&quot; &quot;${COMPREPLY[@]}&quot;)
fi  

} complete -F _systemd_log_hijack systemctl

This isn't a polished solution but it should provide usable bash completion for the non-standard log command verb.

Keep in mind that this is merely a hack to fix poorly-designed UX. The right way would be to somehow convince the SystemD project to accept a fix upsteam.

1

Starting with version 257, journalctl can show the log entries for only the latest (or any other) service invocation, using -I or --invocation=OFFSET.

Show log entries from latest invocation: (equivalent to --invocation=0)

journalctl -u service-name -I

First (oldest) invocation:

journalctl -u service-name --invocation=1

Second latest invocation:

journalctl -u service-name --invocation=-1
Lombra
  • 21