shell2http
shell2http copied to clipboard
Log rotation/limit
I'd like to occasionally start a new log without interrupting the process. While I'm not sure how other operating systems handle it, on macOS I've found that altering the current log file while the program is running seems to prevent further logging. Any help or a fix would be great.
what do you mean altering, maybe is it removing file?
i checked, method with zeroing file via:
printf "" > some.log
and then logging continues to work in the same file from the beginning
but removing of log file cannot work, it works the same in macos/linux
My idea is to reduce a log file, to say, the last say 200 lines or maybe a certain filesize. I think the issue being that if I use programs like sed they create a temp file and then swap out the old file with the new which then seems to prevent any further logging. I suppose it can be done with:
printf "$(tail -200 some.log)" > some.log
I just thought it would be nice to have some sort of log rotation built in.
oh, sorry 😄 I don’t think there is a need to build a rotation system into the program, I want to keep it simple as possible, and all the things that we can do by external tools - do by external tools, e.g. by os, shell scripts, etc
for example, standard way to handling logs in linux - use systemd/syslog, and program just writing logs to stderr/stdout, but syslog can do anything with logs including rotation and much more.
anyway printf "" > some.log works good, what's the point of leaving the last 200 lines?