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
Comments
For added points, it should be possible to generate a list of restarts, something analogous to --list-boots. |
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") |
It should probably make use of |
I don't have that field in my journal yet. Version is 229. |
This feature would be very useful, just to draw some attention to this request 😅 |
Is there an easy way to get the invocation id of a unit? Something like |
Systemd never ceases to surprise how obscure overengineered features get prioritized over very basic usability features
This should be the default for |
@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 |
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.
The text was updated successfully, but these errors were encountered: