0

I currently have a long running application on an embedded Linux environment and all debug messages are currently being outputted to stdout using printf. This isn't ideal for special users who actually need to use the terminal.

Is there is a way to output to a pseudo-device file, a custom stderr or some type of unhooked stream so a live stream can be viewed if users decide to open it up in a file viewer or is there a better way to go about this?

I have thought about just logging all the debug messages to a file but I want to avoid an issue if the application is left running for days and days on end and the log file is left to fill up to some unmanageable size.

  • Just run it in screen and call it a day. – whatsisname Nov 3 '14 at 5:08
2

Well, you can:

  • Use log rotation. After given time, close the log, move it away and open new one.

  • Log to a socket, either UDP or unix domain. In this case the message will be forgotten if you don't have any listener connected.

  • Put some lightweight syslog daemon there and use syslog(3). There you can configure file with rotation, socket and some other options.

  • Use some other framework that already implements options like this.

3

The usual solution is to log to a file, and to use log rotation. You can implement the rotation yourself, or use a daemon like logrotate.

1

Supervisor is a popular process manager which has extensive facilities for capturing and storing output from stdout and stderr for managed processes.

Going towards something that's more accessible, you could use Sentry. It's open source, although there are no C++ clients yet I'm aware of, but it boils down to transporting JSON data over HTTP.

Not the answer you're looking for? Browse other questions tagged or ask your own question.