I want to write mongo logs to syslog on another machine. Reading the mongodb docs, it looks like the only way to use syslog is by writing to the local syslog.
systemLog:
destination: syslog
syslogFacility: local3
A workaround I came up with was to use one of the local facilities, and then use my local syslog to forward the log to the server:
#Forward mongodb logs
local3.* @MY.SYSLOG.SERVER.IP:PORT
Is there a way to specify an IP address in mongo.conf so I don't have to do it this way?
As far as I can tell, there is no way in MongoDB to specify a remote server to write to, but you can do the forwarding in syslog.
Update the rsyslog configuration to forward messages like so:
if($syslogFacility-text == "local3") then{
if($syslogTag contains "mongod") then{
action(type="omfwd" target="MY.SYSLOG.SERVER.IP" port="PORT" protocol="udp")
stop
}
}
According to rsyslog docs, the local3.* @MY.SYSLOG.SERVER.IP:PORT
syntax is deprecated, so use omfwd
instead.