Redirecting standard output to syslog

Ivan Vučica picture Ivan Vučica · Mar 20, 2009 · Viewed 12.6k times · Source

I'm planning to package OpenTibia Server for Debian. One of the things I want to do is add startup via /etc/init.d and daemonization of the otserv process.

Thing is, we should probably redirect output to syslog. This is usually done via the syslog() function. Currently, the code is swarmed with:

std::cout << "Stuff to printout" << std::endl;

Is there a proper, easy to add, way to redirect standard output and standard error output into syslog without replacing every single "call" to std::cout and friends?

Answer

Alnitak picture Alnitak · Mar 20, 2009

You can pipe your stdout to syslog with the logger command:

NAME

 logger - a shell command interface to the syslog(3) system log module

SYNOPSIS

 logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message ...]

DESCRIPTION

 Logger makes entries in the system log.  It provides a shell command
 interface to the syslog(3) system log module.

If you don't supply a message on the command line it reads stdin