haskell-hvr / hslogger

Logging framework for Haskell
https://hackage.haskell.org/package/hslogger
BSD 3-Clause "New" or "Revised" License
64 stars 36 forks source link

hslogger doesn't seem to work with syslog-ng #1

Closed jgoerzen closed 11 years ago

jgoerzen commented 14 years ago

http://software.complete.org/software/issues/show/178

Added by Magnus Therning 2009-08-23. ALL TEXT BELOW FROM SUBMITTER.

On my Arch system I ran into the following problem:

> :m +System.Log.Logger
> :m +System.Log.Handler.Syslog
> sl <- openlog "foo" [PID] USER DEBUG
> updateGlobalLogger rootLoggerName (addHandler sl)
> warningM "bar" "test" 
*** Exception: sendTo: protocol error (Protocol wrong type for socket)

I also tried using a UDP socket (by modifying the syslog-ng config to include @unix-dgram("/dev/dlog")), but that doesn't seem to fix it:

> :m +System.Log.Logger
> :m +System.Log.Handler.Syslog
> sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG
> updateGlobalLogger rootLoggerName (addHandler sl)
> warningM "bar" "test" 
*** Exception: sendTo: protocol error (Protocol wrong type for socket)

I've tried the same on a Debian box. With sysklogd I don't have any problems, but after switching to syslog-ng I see exactly the same behaviour as on my Arch system.

The version on Arch is 1.0.7, and the version on Debian is 1.0.8. (Have you forgot to push the latest version to Hackage again? ;-)

http://article.gmane.org/gmane.comp.lang.haskell.cafe/62709

trofi commented 11 years ago

Yeah, it depends on the socket type of /dev/log.

If you have unix-stream("/dev/log"); then thing don't work unix-dgram("/dev/log"); works fine though

I've hacked a workaround which switches from one to another: https://github.com/gentoo-haskell/gentoo-haskell/blob/master/dev-haskell/hslogger/files/hslogger-1.2.1-use-STREAM.patch

glibc's syslog() function tries stateless approach first, then stateful:

$ strace logger test
...
socket(PF_FILE, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 1
connect(1, {sa_family=AF_FILE, sun_path="/dev/log"}, 110) = -1 EPROTOTYPE (Protocol wrong type for socket)
close(1)                                = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC, 0) = 1
connect(1, {sa_family=AF_FILE, sun_path="/dev/log"}, 110) = 0
sendto(1, "<13>Feb 18 19:52:41 st: test\0", 29, MSG_NOSIGNAL, NULL, 0) = 29
close(1)                                = 0
trofi commented 11 years ago

This fix should be a bit better:

https://github.com/gentoo-haskell/gentoo-haskell/blob/master/dev-haskell/hslogger/files/hslogger-1.2.1-dev-log-rdetect.patch