Further investigation showed that the issue seems to occur only inside LXD containers, not in regular VMs. Sorry, I'm so used to working in containers these days that I didn't even think to check a VM as well.
The exit status is 0 either way, so my scripts don't terminate because of this error. However, messages not being logged when they should be is still a problem, as is spurious error messages in (frequently running) cron jobs, which then flood my inbox.
Further investigation showed that the issue seems to occur only inside LXD containers, not in regular VMs. Sorry, I'm so used to working in containers these days that I didn't even think to check a VM as well.
Steps to reproduce:
apt-get install lxd-installer
lxd init
lxc launch ubuntu:jammy ct0
lxc exec ct0 -- bash
Then within the container run
echo foo | logger --id="$$"
Note: the command may work the first time, but subsequent invocations then produced the error described in my bug report.
Another detail is that the error does not seem to occur when --id is used without an argument:
root@ct0:~# echo "foo" | logger --id
root@ct0:~# echo "foo" | logger --id="$$"
logger: send message failed: Invalid argument
The exit status is 0 either way, so my scripts don't terminate because of this error. However, messages not being logged when they should be is still a problem, as is spurious error messages in (frequently running) cron jobs, which then flood my inbox.