Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deliver messages from logger when reading from unix sockets #20

Open
fabiokung opened this issue Mar 21, 2013 · 5 comments
Open

Deliver messages from logger when reading from unix sockets #20

fabiokung opened this issue Mar 21, 2013 · 5 comments

Comments

@fabiokung
Copy link
Collaborator

logger by default writes to /dev/log (a regular unix domain socket). Custom sockets can be specified with -u, so that logger can write to a unix socket where a log-shuttle process listens.

However, logger doesn't generate newlines, and uses a syslog format slightly different from what logplex expects:

# write logs
$ echo -e "message1\n" | logger -u /tmp/test.sock -t mytoken -p user.notice
$ echo -e "message2\n" | logger -u /tmp/test.sock -t mytoken -p user.notice

# read logs
$ while true; do rm /tmp/test.sock ; nc -l -U /tmp/test.sock ; done
<13>Mar 21 00:33:21 mytoken: message1<13>Mar 21 00:33:21 mytoken: <13>Mar 21 00:33:25 mytoken: message2<13>Mar 21 00:33:25 mytoken:

To support this, log-shuttle needs to detect the \000 (UNIX end of line) character at the end of messages, instead of relying on \n and \r. Maybe it already does, but I am not sure if logplex will accept the syslog body as logger generates it:

$ echo -e "message2\n" | logger -u /tmp/test.sock -t mytoken -p user.notice
$ echo -e "message3\n" | logger -u /tmp/test.sock -t mytoken -p user.notice
irb(main):001:0> UNIXServer.open("/tmp/test.sock") { |s| loop { sock = s.accept; $stdout.puts sock.read.inspect; sock.close } }
"<13>Mar 21 00:53:42 mytoken: message2\000<13>Mar 21 00:53:42 mytoken: \000"
"<13>Mar 21 00:53:44 mytoken: message3\000<13>Mar 21 00:53:44 mytoken: \000"

/cc @ryandotsmith @fdr

@fabiokung
Copy link
Collaborator Author

I forgot to mention that I opened this issue just to throw the idea. I'll happily help implementing it as soon as I can, unless someone else beats me to it.

@fabiokung
Copy link
Collaborator Author

Quick update on this: I was wrong, logger does not send to logs to /dev/log by default, it probably uses the syslog(3) family of functions.

Everything else remains true when a custom domain socket is specified with -u though.

An alternative would be to make an instance of log-shuttle serve calls to the syslog(3) family of functions.

@ryandotsmith
Copy link
Owner

@fabiokung it is not clear to me how we can connect logger to logplex. For example, using SYSLOG(3)

#include <syslog.h>

int
main()
{
        syslog(LOG_ALERT, "hello world");
}

The following message makes it into system log stream.

$ tail -f /var/log/system.log
May 31 11:05:09 b.local x[76342]: hello world

Unless we can control the output format of SYSLOG(3), we will need to receive the formatted messages from SYSLOG(3) and rewrite them to be compatible with RFC5424. This seems like it is out of scope for log-shuttle.

@fabiokung
Copy link
Collaborator Author

I did some more research on this. POSIX doesn't say anything about where syslog(3) messages should be sent to:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html

But glibc's implementation will always write to a /dev/log dgram unix socket:

http://www.gnu.org/software/libc/manual/html_node/syslog_003b-vsyslog.html#syslog_003b-vsyslog

It is safe to assume that on linux systems all syslog(3) messages will be written to /dev/log. Both syslogd and syslog-ng read logs from there by default.

@fabiokung
Copy link
Collaborator Author

Moved to heroku/log-shuttle#14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants