Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

journalctl -u 'xxx' - add switch to show logs since unit restart #1942

Open
zabbal opened this issue Nov 18, 2015 · 8 comments
Open

journalctl -u 'xxx' - add switch to show logs since unit restart #1942

zabbal opened this issue Nov 18, 2015 · 8 comments
Labels
journal RFE 🎁 Request for Enhancement, i.e. a feature request

Comments

@zabbal
Copy link

zabbal commented Nov 18, 2015

When debugging misbehaving service which you've got to restart after changing configuration it's really handy to be able to see just the logs from latest run - I mean after running "systemctl restart xxx".

The unit is restarted by systemd so it "knows" when it happened precisely. Would be great if I could use this from within journalctl as well without manually copy-pasting time back and forth. Smth like:
journalctl -u xxx --since-unit-restart

It's in essence similar to journalctl -b but on per-unit, not per-system basis.

@keszybz
Copy link
Member

keszybz commented Nov 28, 2015

For added points, it should be possible to generate a list of restarts, something analogous to --list-boots.

@poettering poettering added RFE 🎁 Request for Enhancement, i.e. a feature request journal labels Apr 18, 2016
@towolf
Copy link

towolf commented Jan 25, 2017

I had to make a really hacky bash script to achieve something similar.

Somehow the 'big race' in journal that remains a big problem, also plays into this.

Journal seems to have no good way of correlating service start and journal timestamps.

#!/bin/bash
#

[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :

# Timestamp when unit transitioned from inactive to active
since=$(systemctl show -p InactiveExitTimestamp "$1" | cut -f 2 -d '=' | cut -f 2-3 -d' ')
# or one minute if unset
since=${since:-1 min ago}

# Get prefix string that this units logs with: most robust
# https://github.com/systemd/systemd/issues/2913#issuecomment-219702148
id=$(systemctl show -p SyslogIdentifier "$1" | cut -f 2 -d '=')

# Get all raw output from unit since start, only from stdout&stderr
# Considering that backend only logs "bad" stack traces to stderr, this should
# always be relevant
service_trace=$(journalctl -o cat --since "$since" -t "$id")

@fsateler
Copy link
Member

It should probably make use of _SYSTEMD_INVOCATION_ID as introduced by #4067

@towolf
Copy link

towolf commented Jan 28, 2017

I don't have that field in my journal yet. Version is 229.

@dvaerum
Copy link

dvaerum commented Jul 11, 2022

This feature would be very useful, just to draw some attention to this request 😅

@sedrubal
Copy link

It should probably make use of _SYSTEMD_INVOCATION_ID as introduced by #4067

Is there an easy way to get the invocation id of a unit? Something like --list-boots?

@laurivosandi
Copy link

laurivosandi commented Aug 18, 2023

Systemd never ceases to surprise how obscure overengineered features get prioritized over very basic usability features

journalctl -u foobar.service  _SYSTEMD_INVOCATION_ID="$(systemctl show -p InvocationID --value foobar.service)"

This should be the default for journalctl -u foobar

@SjonHortensius
Copy link
Contributor

@laurivosandi you are free to send a PR to implement this, right? Also, what constitutes a basic feature versus an obscure feature seems pretty subjective to me.

Your oneliner is pretty nice by the way, I'll make an alias out of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
journal RFE 🎁 Request for Enhancement, i.e. a feature request
Development

No branches or pull requests

9 participants