1

Do uClibc/glibc provide any feature to redirect errors to syslog? The erros like "can't resolve symbol" need to go to syslog instead of stderr on console.

Lunar Mushrooms
  • 8,358
  • 18
  • 66
  • 88
  • 2
    here the same question on SO http://stackoverflow.com/questions/665509/redirecting-standard-output-to-syslog – Sergei Nikulov Nov 18 '11 at 12:29
  • 1
    Why are such errors happening in the first place? Any message generated by libc indicates bugs in your program or build toolchain, and should not happen in a production environment... – R.. GitHub STOP HELPING ICE Nov 18 '11 at 14:34
  • I want to make sure that such errors are not happening in production environment. I am happy if syslog is empty after execution of production code :-). But I need to confirm it by looking into syslog. Note that it is notonly about coding. Some funny user could load an old version of library in production environment. Without a logging system , this would be tough. – Lunar Mushrooms Nov 18 '11 at 14:51
  • @LunarMushrooms: For glibc Fred has already provided the links. syslog calls are available on uClibc (atleast from looking @ the source) [syslog.h](http://git.uclibc.org/uClibc/tree/include/sys/syslog.h) & [syslog.c](http://git.uclibc.org/uClibc/tree/libc/misc/syslog/syslog.c) – another.anon.coward Nov 18 '11 at 15:06
  • What is tricky here is, the errors produced inside glibc code (like can't resolve symbol) also need to be logged. Not only the application errors. I had a quick look at the sources of uclibc. I couldnt find any kind of redirection to syslog there (it implements syslog anyway). So I believe there is no such feature exists. – Lunar Mushrooms Nov 18 '11 at 15:21

1 Answers1

0

If it's a daemon, the best option is using an init capable of this (e.g. InitNG). If this isn't possible, you can replace stderr early (not as nice, but if there's no other option...):

#!/bin/sh
init 2>&1 >/dev/console | tee /dev/console | logger

Something similar needs to be done for programs using pseudo-terminals. The easiest way is using a shell wrapper similar to the above snippet.

Ismael Luceno
  • 2,055
  • 15
  • 26