The Setup
I have this in my /etc/rsyslog.conf
:
$template local1DynFile,"/path/to/my/log/%programname%.log.%NOW%
$template local1LogFormat,"%msg:2:$:%\n"
*,*;auth,authpriv,local0,local1.none ~/var/log/syslog
local1.* ?local1DynFile;local1LogFormat
Then I have the following Python script (test.py
):
import logging
import logging.handlers
logger = logging.getLogger('pxet.foo')
logger.addHandler(logging.handlers.SysLogHandler(address='/run/systemd/journal/syslog', facility='local1'))
logger.handlers[0].setLevel(logging.DEBUG)
logger.setLevel(logging.DEBUG)
logger.debug('test cockroach is a bug')
The Problem
If I do the following:
rm -rf /path/to/my/log
systemctl restart rsyslog
python test.py
I get no log message. However:
mkdir -p /path/to/my/log
python test.py
And it all works.
The Question
Is it possible for me to make rsyslog
create the directories if they do not exist, or do I have to do that myself?
The documentation (http://www.rsyslog.com/doc/v8-stable/configuration/action/index.html#omfile-specific-configuration-statements) says that rsyslog has the
$CreateDirs
legacy configuration option to control whether or not to create directories an as needed. (There is a similarly named optionCreateDirs
for the next configuration format, but your example uses the legacy format.) So try the line:$CreateDirs on
just before your
local1.* ?local1DynFile;local1LogFormat
line.