I’ve been trying to set up logging in Linux for one of my Edge drivers so that the log output is continuously saved to a file, but I’m running up against a flushing issue. No logging output (besides the initial ‘connecting’ and listening for logs’ messages) is written to the file until I Ctrl-c out of the CLI logging command:
st edge:drivers:logcat <driverId> --hub-address 192.168.1.101 >> logs/as_edge.log 2>&1
I’ve tried various remedies recommended in stackoverflow, such as using stdbuf, but nothing seems to work. I want to be able to run tail on it to monitor the file when needed, and also have a periodic log rotation process.
Is there anything I can do to address the flush problem or would that require a fix to the CLI itself?
Hi @TAustin, I did some quick tests and using both redirection and tee to concurrently write to stdout and file. I only saw the buffering change when redirecting stdout as well as stderr (2>&1) which I suspect is some result of the fancy output of the live logger. I believe all the logs get emitted to stdout so redirecting stderr probably isn’t required.
Here’s what I ran to tee the output with append.
$ smartthings edge:drivers:logcat --hub-address=192.168.1.4 -a \
| tee -a driver-logs.txt
No problem, FWIW I think the problem was actually realted to stderr redirection to stdout which was changing the stdout buffering. I believe removing 2>&1 from your original command should work as well (but tee is nice for also seeing the live output). At least that is what I was seeing in my testing.