2

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?

1 Answer 1

4

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 option CreateDirs 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.

1
  • Perfect! There was much googling (e.g. rsyslog create directory) to no avail. It would appear that Centos7 comes with rsyslog v7 (i.e. legacy config)... but adding that to my config works. Jan 5, 2016 at 15:37

You must log in to answer this question.

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