all 16 comments

[–][deleted] 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (4 children)

[–]fschmidt[S] 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (3 children)

I need to write a post on why configuration files should be banned. Maybe next shabbat.

[–]x0x7 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (2 children)

Well that's the dumbest thing I've ever heard. I could understand an argument against centralized config files. But I run log rotate on my logs with the config file in the source code directory and the software just calls exec("logrotate -f theconfigfile") on an interval. Then log rotate handles all the business logic seperate from my code, and I get to "code" the log storage behavior in a "language" designed for that task.

[–]fschmidt[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (1 child)

Then log rotate handles all the business logic seperate from my code, and I get to "code" the log storage behavior in a "language" designed for that task.

Pointless separation is one big source of complexity. There is no reason for an end-user to ever configure logging. The app code should do that. And so it might as well do it purely through code, so no need for logrotate.

[–]trident765 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (0 children)

Pointless separation is one big source of complexity

I was just thinking about this the other day. It's the thing people say to sound smart. People say to keep X and Y separate because it makes them look like they had the foresight to prevent some bad thing from happening if you mix X and Y. So people are stuck maintaining this pointless separation because if they were to question it they would look like stupid people who didn't have the foresight to understand why you have to keep X and Y separate.

[–][deleted] 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (0 children)

That LogJ4 shit you linked is peak OO stupidity. IDK why people do that to themselves.

[–]trident765 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (1 child)

Doesn't this run the risk of running out of filenames if the user specifies too few?

[–]fschmidt[S] 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (0 children)

No, the last file is just dumped. No need to keep logs forever.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (7 children)

Why don't you just rename the file if it's too big and call it a day?

[–]x0x7 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (1 child)

One reason that things like logrotate exists is that if you rename it, the open file descriptor in the program still points to it and will continue appending to it. For that you use a copy truncate. If you were to script it yourself you would copy the log to a file of the same name plus a timestamp, run truncate -s0 file to move all future appends to the front of the file, and then take any prior copies besides the most immediate one and gzip them, then take all that are so old you couldn't possibly care about them and delete them.

Or you can just have logrotate do that for you.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (0 children)

Gotcha. Hey thanks man, I appreciate you taking the time to explain it.

[–]fschmidt[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (4 children)

Yes, it's "rolled over" by renaming it.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (3 children)

What I'm asking is why is this not 2 lines?

If filesize(logfile) >= arbitrary_amount
Rename(logfile, current_date + ".log")

It's been a long time since I've done this shit, maybe I'm missing something you're doing

[–]fschmidt[S] 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (2 children)

The only reason for more code is to allow multiple rolling backup files. Here is the code, it is quite simple.

[–][deleted] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (1 child)

I just didn't get why anything was moved, but x0 said it had to do with file descriptor staying open. That makes sense.

[–]fschmidt[S] 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (0 children)

That only makes sense if this is done by an outside process. Since I am doing it in code in the same process, I just close the file descriptor, move the file, and open a new file descriptor. So none of the issues mentioned by x0x7 apply.