I use a similar script, because the way I understand it, if I redirect logs like you suggest, I would lose the ability to run docker logs storagenode --since .... and would have figure out how to get the correct portion of the log from the file.
My script runs docker logs storagenode -f and redirects it to a file. The files are numbered and the number is incremented every time I (re)start the node.
Yes, if you setup log to the file, you will not be able to use docker logs command (it will return empty).
To search portion of the file it is easy to do so, but you should use different tools.
For example, to get logs for 2021-11-01, you need to filter them like this:
I run my monitoring script every minute or so and only need the portion of the log since the last time the script ran. This is very easy to do with docker logs --since .., I just save a timestamp of when the script ran and use it next time. Another script takes “the last two minutes” (--since 2m) of the log. I’m sure I could figure out how to do both with just a file (and would have to if the fie was the only option), but docker logs (and running screen to save the log to a file as a backup) is just easier.
That date command is very flexible, you can use relative dates (“now-1 hours” or “1 hour ago”) or just absolute dates(“2021-11-02 08:00”). I’m guessing similar to the --since option with docker. If you want you can stick that in a script and use parameters for sdat, edat and filename to simplify.
All of this would save you from having to go through the entire docker log every few minutes to add some new lines.
well it works fine and i don’t see any advantages in changing it… also been working on a failsafe shutdown part of it, but haven’t gotten that working… but maybe if i actually spent some more time on it then that would help lol
@BrightSilence yeah i can see how that would do pretty much the same thing, it wouldn’t change the log name tho since docker will not allow the change of the name while the log is running.
sure then i could learn to use logrotate, but on top of that it would also take away my ability to use successrate.sh on the different logs across different nodes defined by wild cards.
i’m sure if i set it up differently from the beginning there would be other reasons i wouldn’t want to change to my solution either.
it works for me and i like how it works.
especially the whole successrate.sh with wildcards.
so i can successrate all nodes for the last day or 10 days or a single node for 10 days.
and when i start nodes i can just do a docker logs --tail 200 sn0001
then change the 1 to 2 and so on and so forth.
making it quick to see everything is running correctly, even if i don’t use it that much lol
No it wouldn’t, you could just point it to the files exported by the nodes. It can work with either containers or files.
I’m not saying you should change it, but I do literally all the things you say you can’t do, while also redirecting logs to a file. So I’m just providing alternative options for anyone else who comes across this thread. It’s definitely all possible.