CARMA C++
SyslogRedirector.h
1 #ifndef CARMA_UTIL_SYSLOGREDIRECTOR_H
2 #define CARMA_UTIL_SYSLOGREDIRECTOR_H
3 
4 #include <string>
5 
6 namespace carma {
7 namespace util {
8 
9 /*
10  * Force all glibc error messages to go to stderr
11  *
12  * By default, glibc prints error messages using the internal function
13  * __libc_message(). By default, this will send the error message and associated
14  * backtrace to the controlling TTY. If that fails, the error message (but not
15  * the associated backtrace) to syslog.
16  *
17  * However, glibc has a nice feature where you can force all output to go to
18  * stderr rather than the controlling TTY. The syslog fallback will be called if
19  * stderr fails for some reason.
20  *
21  * In order to capture both the message and associated backtrace from glibc
22  * error messages, it is useful to force the output to stderr.
23  */
24 void forceGlibcErrorsToStderr();
25 
26 /*
27  * Redirect any file descriptor to syslog
28  *
29  * This is most commonly used to redirect stdout or stderr to syslog and
30  * therefore capture the output that would otherwise be lost.
31  *
32  * This is especially useful when there is a desire to capture glibc error
33  * messages, such as the ones that result from heap corruption and abort
34  * the program.
35  */
36 void redirectFdToSyslog(int fd, const std::string &fdname);
37 
38 } // namespace carma::util
39 } // namespace carma
40 
41 #endif /* CARMA_UTIL_SYSLOGREDIRECTOR_H */
42 
43 /* vim: set ts=8 sts=8 sw=8 noet tw=92: */