drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.62k stars 1.12k forks source link

Question about log buffer for default LOG functions #2182

Closed Leviathan856 closed 1 month ago

Leviathan856 commented 1 month ago

Installation: latest Docker Hub image (same behavior is present on MacOs (installed with homebrew) when binary file output is redirected to the file via ">").

I’m encountering an issue where log output appears in Docker Desktop app or log file only after ERROR messages (LOG_ERROR << ...) or when Docker container is being stopped. As I understand messages are saved to a buffer and the buffer is flushed when error message should be printed or after receiving SIGTERM signal. That is why most of logs are not printed in real-time.

Is this expected behavior, and if so, is there a way to configure it so I can view the logs in real-time?

If needed, I’d be happy to provide my project files for further investigation.

Thanks in advance for your help!

an-tao commented 1 month ago

This might be related to the buffering mechanism of logging. For performance reasons, low-level logs do not flush the buffer immediately. You should use Drogon's file logging instead of outputting to standard output, as file logging forces a flush every second.

Leviathan856 commented 1 month ago

Yes, it works! But I needed to create additional log file for storing all messages (used tail -f to make it work in real-time) because symlinking original .log file to stdout didn't work for me. Also all this work should run separately from container's main process (e.g. using bash script)

Thank you very much for clarification!