I have severals servers logging to the central syslog server, which collect the logs using syslog-ng.
I send logs with a tag using the logger command :
$ logger -n 01.02.03.04 "Hello from $HOST at $(date)" -t MY_SPECIFIC_TAG -p local2.error
Using syslog-ng, the message is then written as following :
Mar 5 23:36:04 05.06.07.08 MY_SPECIFIC_TAG: Hello from vps1234567 at Tue Mar 5 23:36:04 CET 2019
My aim is to make all applications (java, apache, mysql,...) send their logs using a tag that identify the app generating the message, so I can write the logs on my syslog-server in a file matching the name of the app.
Is it possible to extract the string MY_SPECIFIC_TAG from the message, and use it as a variable in the path of file ?
This extraction needs to be perform in the syslog-ng configuration file, so I can write the destinations as following:
destination dst_custom{
file("${MY_SPECIFIC_TAG}-${FACILITY}-${LEVEL}-${YEAR}-${MONTH}-${DAY}.log");
};