1

enter code hereI have a C++ application running on an Embedded Linux device which uses systemd.

If I wish to stream the debug output of my services / processes, I SSH into the device and execute command journalctl -u <my_systemd_service>.service -f from the terminal, where <my_systemd_service> is my actual service name.

Now the issue is that during production, I'd like to have SSH disabled for security reasons. However, I would still like to be retrieve the debug output sometimes, triggered by sending an MQTT command to the device as the device is connected to an MQTT broker.

Is there a way to get my debug output from within the C++ code itself when the MQTT command is received?

I don't suppose using system() would be ideal. For example system("journalctl -u <my_systemd_service>.service -f") ? Of course this would also need to run in a separate thread if so. Any recommendations would be appreciated.

hardillb
  • 54,545
  • 11
  • 67
  • 105
Engineer999
  • 3,683
  • 6
  • 33
  • 71

1 Answers1

0

You can direct service stdout/stderr to a file then read it using std::fstream whenever you need. You might want to see this: https://stackoverflow.com/a/43830129/11277878

no more sigsegv
  • 468
  • 5
  • 17
  • Thanks for your reply. I have so much debug output and a little bit worried about continuously writing to a file 24/7. I guess writing to a file in RAMdisk would be better than writing to a file in Flash anyways? – Engineer999 Sep 28 '21 at 14:46
  • You are right. I'm not a logging expert but in addition to my answer, I can also suggest classifying output messages with a console interface. You can enumerate output types as error, info, warning etc. then maybe log only panicky ones to a file so you it will consume less space. Also you can locate your log file under /tmp so it will be removed on next boot. – no more sigsegv Sep 28 '21 at 14:54