90

I'm tailing logs of my own app and postgres.

tail -f /tmp/myapp.log /var/log/postgresql/postgresql.main.log

I need to include pgpool's logs. It used to be syslog but now it is in journalctl.

Is there a way to tie tail -f && journalctl -f together?

5 Answers 5

144

You could use:

journalctl -u service-name -f

-f, --follow

Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.

Here I've added "service-name" to distinguish this answer from others; you substitute the actual service name instead of the text service-name.

21

You could forward your log entries to journal:

systemd-cat tail -f /tmp/myapp.log /var/log/postgresql.log

and then use journalctl -f... though as Mark mentioned, that will print all journal entries.


One way to filter only the messages from those logs and from that particular unit is to use a distinct SYSLOG_IDENTIFIER i.e. edit the unit file and under the [Service] section add e.g.

SyslogIdentifier=my_stuff

restart the unit then run systemd-cat with the same identifier

systemd-cat -t my_stuff tail -f /tmp/myapp.log /var/log/postgresql.log

and finally query the journal only for that particular identifier:

journalctl -f -t my_stuff
5

If you have bash available, you can use process substitution as one of the tail parameters:

tail -f /tmp/myapp.log /var/log/postgresql/postgresql.main.log <(journalctl -f)
3
  • 1
    This is the elegant way I also tried, but is doesn't work. Tail shows that it's using /dev/fd/xx, but no logs are displayed.
    – bikey
    Oct 7, 2016 at 15:12
  • correct; /dev/fd/xxx is the temporary pipe that bash uses in order to implement the process substitution; any journalctl output will show up in there.
    – Jeff Schaller
    Oct 7, 2016 at 15:13
  • 5
    You probably don't want to follow the whole journal but just those for the pgpool unit. Assuming the service named pgpool.service, try journalctl -fu pgpool.service. Also, if you are not running this as root, make sure the user is in the systemd-journal group! Oct 10, 2016 at 13:50
1

try something like:

tail -f /tmp/myapp.log >> /tmp/tail.log &
journalctl -f >> /tmp/tail.log &
tail -f /tmp/tail.log
0

Using journaltail:

journaltail --unit pgpool.service /tmp/myapp.log /var/log/postgresql/postgresql.main.log

I just threw the script together an hour ago after looking for a solution at stackoverflow et al.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .