I am logging messages like this in perl –
syslog ("LOG_INFO", "this is info");
syslog ("LOG_WARNING", "this is warning");
when I see these messages, I get this-
Nov 15 20:20:47 ubuntu tag-0.0.2[13399]: this is info
Nov 15 20:20:47 ubuntu tag-0.0.2[13399]: this is warning
The word “ubuntu” in syslog message happens to be host name of the local host.
Is there a way I can log locally and but specify a hostname?
My app processes data from other hosts and logs information about them. It will be great if I can specify the host name when I log messages, this way I can use third party tools easily as they can easily filter out logs based upon hostname.
btw, if I can add additional question- why are the logs not showing level of message? shouldn’t I expect to see “info” in info syslog message I am logging ?
Probably the easiest way to accomplish this task is to set the
syslogto receive messages over the network. Forrsyslog, this is often in/etc/rsyslog.conf:I’m using UDP here because it is easy to do on just about any
syslogdaemon and demonstrating it is easy:In short: the
<nnn>represents the facility and priority, as described in section 4.1.1 of the RFC. The timestamp is highly specified in 4.1.2: in short, three-letter English month abbreviations, no leading0— instead a leading space:Aug__8rather thanAug_8(underscores used because spaces collapse in code blocks). The hostname can’t have any domain portions. IP addresses are fine, both IPv4 and IPv6.You could also use Unix domain sockets (
unix(7)) such as/dev/log. That would be more reliable than UDP.