1

I'm having trouble redirecting Boost-generated logs from the shell. We start out simply enough with an application that successfully logs to stdout.

cjholmes$ ./my_application
[2017-03-14 10:21:16.920355] [0x00007fff79497300] [info]    Boost log severity set to trace
[2017-03-14 10:21:16.921071] [0x0000000101282000] [trace]   Adding "/Users/cjholmes/Desktop/idsconnector/ca/DigiCertHighAssuranceEVRootCA.pem"
[2017-03-14 10:21:16.921233] [0x0000000101282000] [trace]   Adding "/Users/cjholmes/Desktop/idsconnector/ca/DigiCertSHA2HighAssuranceServerCA.pem"

Easy, right? So I should be able to do this:

cjholmes$ ./my_application > log.txt

No output is sent to the console (which is expected), but when I look in the log.txt file, it is empty. The shell creates the file, but the file is always empty.

I have tried all of the usual redirection syntaxes too, and none of them work. Also, I have tried explicitly initializing the log with std::cout:

boost::log::add_console_log(std::cout);

I still get the same result. I can always get the log data on the console, but redirecting the output somehow loses all my log data.

What am I missing?

slashingweapon
  • 11,007
  • 4
  • 31
  • 50
  • It looks like this has been asked here: http://stackoverflow.com/questions/35581297/boost-log-trivial-severity-does-not-redirect-to-a-file. Although you don't mention nohup or process forking, I still think you should look into the environment of your application. I.e. how the shell operates, permissions, filesystem free space, etc. You can verify if the log records are being written with strace. – Andrey Semashev Mar 15 '17 at 17:30
  • I'm not doing anything special with stdin on this program, I don't close or duplicate or replace the file handle. This application does not fork or exec. This problem can be reproduced when I run from the command line and when I run it from init.d. The bug can be replicated across operating systems (MacOS, Linux) and multiple architectures (x86, ARMv6). The file is being created, so permissions aren't the issue. – slashingweapon Mar 15 '17 at 19:55
  • Well, it works on my Kubuntu with the "trivial" example from Boost.Log, so it must be something specific to your system. Did you try strace? – Andrey Semashev Mar 16 '17 at 10:41
  • What happens if you run this under `pty` (on linux) as "`pty ./my_application > log.txt`"? Do you see anything in `log.txt`? I'm just wondering if [`isatty`](http://man7.org/linux/man-pages/man3/isatty.3.html) or similar is being called against the file descriptor associated with `std::cout`. – G.M. Mar 17 '17 at 12:41
  • @G.M.: Boost.Log does not perform any detection if the output is written to a terminal. – Andrey Semashev Mar 18 '17 at 12:47
  • I'm not necessarily suggesting any such detection is performed by `boost::log` itself -- simply that something somewhere might be doing such a test on the file descriptor and taking action that might affect the output on said descriptor. – G.M. Mar 18 '17 at 12:57
  • Have you been able to resolve this issue @slashingweapon? I'm having the same problem on Ubuntu with trivial boost logging messages. – Andrea Rendl-Pitrey Feb 27 '18 at 19:40

0 Answers0