What is logger?
Logger is a unix command apparently first appearing in 4.3 BSD back in 1993. The manpage also says "The logger command is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible."
Logger writes messages to the system log via syslog. Therefore, it is useful for adding custom messages to your system logs. This can be useful in either testing or monitoring type situations.
I've found logger to be available on most any reasonable *NIX type system (My Mac OS 10 box has it in /usr/bin/!). Not only that, but I've found the version under OS X, FreeBSD, and Linux to be the same! (wha-hoo compatability!)
logger [-is] [-f file] [-p pri] [-t tag] [message ...]
To add the message "this is a test" to the system log:
$ logger this is a testWhich leaves this line in the system log:
Sep 20 06:44:13 localhost dl: this is a test
Notice that in that example, the "service" listed was my username, "dl". Often, this is not what we want. You could specify the service using the '-t' option like this:
$ logger -t test-service this is a testWhich leaves this line in the system log:
Sep 20 06:46:56 localhost test-service: this is a test
Now, we have specified the name of the "service" that is logged. Often, an actual syslog message will contain the PID of the service logging the message. This can be accomplished by also passing the '-i' option to logger like this:
$ logger -i -t test-service this is a testWhich leaves this line in the system log:
Sep 20 06:50:11 localhost test-service: this is a test
What if we want several messages to all originate from the same service with the same PID? That can be accomplished by writing all of the messages to a file and specifying that file with the '-f' option to logger like this:
$ cat /tmp/testlog first test message second test message third test message $ logger -i -t test-service -f /tmp/testlogwould leave the following 3 lines in the system log:
Sep 20 06:53:17 localhost test-service: first test message Sep 20 06:53:17 localhost test-service: second test message Sep 20 06:53:17 localhost test-service: third test message
Finally, if we have syslogd configured to log messages of different priorities to different places, we may specify the priority we would like with the '-p' option, like this:
$ logger -i -p local3.info -t test-service this is a testWhich would leave the following line in the system log where local3.info messages are sent:
Sep 20 07:15:32 localhost test-service: this is a test