To test syslog, you have to setup syslog. Setting up syslog is system-specific and potentially quite variable because they frequently run syslogd replacements like rsyslogd (Ubuntu) or syslogd-ng. OSX has it's own internal system logger (the apple system logger) that supports the syslog API, but then adds additional stuff (like the 'syslog' command line application).
The idea is to add syslog configs to write to '/var/log/local2.log' for the local2 facility. In all cases, test with this:
logger -s -p local2.info -t example hello world
grep example /var/log/local2.log
Should print the 'hello world' log. These tests allow an alternate log file and/or facility via the SYSLOG_TEST_LOG_FILE and SYSLOG_TEST_FACILITY environment variables.
OS X has a fairly standard config, for a fairly standard syslogd (although it does not have the bells of something like the syslogd on FreeBSD).
Add to /etc/syslog.conf
local2.* /var/log/local2.log
Then restart syslogd:
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
Given the actual behavior of what successfully transmits over UDP and writes to a log file, it's a bad idea to rely on messages longer than 1k. There's a break point somewhere between 1k and 2k.
It's a good idea to intentionally use string formatting, to prevent the chance of extra arguments getting passed in and busting Syslog. Lastly, null characters need to be escaped to prevent truncation, and there is some strange escaping with carriage returns and line feeds. Basically the best practice is to scrub for anything but alphanumeric and punctuation characters.
From the Transmission of Syslog Messages over UDP RFC:
IPv4 syslog receivers MUST be able to receive datagrams with message
sizes up to and including 480 octets. IPv6 syslog receivers MUST be
able to receive datagrams with message sizes up to and including 1180
octets. All syslog receivers SHOULD be able to receive datagrams
with message sizes of up to and including 2048 octets. The ability
to receive larger messages is encouraged.
See also the Syslog Protocol RFC.
How did you get gist to allow you to use
/in the filenames?When I try this, I get an error message:
I've been wanting to be able to do this for a long time. Any help is appreciated :)