natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.81k stars 593 forks source link

Can support custom file permissions? #164

Open machine3 opened 2 years ago

machine3 commented 2 years ago

https://github.com/natefinch/lumberjack/blob/v3/lumberjack.go#L255

I want to replace 600 with 644

natefinch commented 2 years ago

Lumberjack will copy the permissions of the existing file when it creates the new file. See here: https://github.com/natefinch/lumberjack/blob/v3/lumberjack.go#L267

So if you want different file permissions, the easiest thing to do is create the file with the permissions you want, first.

machine3 commented 2 years ago

@natefinch But the file is generated by calling the r.openExistingOrNew(). r.openExistingOrNew() will call r.openNew(), and then create the file with the default permissions. Can you add a mode parameter to the struct Roller and let the user set it by himself?

natefinch commented 2 years ago

If you create the file in your own code with the right permissions, lumberjack will copy those permissions to the new file when it rolls over.

It creates the file with default permissions and then changes those permissions to match the permissions on the previous file.

counten commented 2 years ago

There are many people have the requirement to custom the permission of the log file or even the log dir @machine3 . I can push a PR to custom the permission with addition mode parameter for this requirement, and I want to make sure if you support this change。@natefinch

natefinch commented 2 years ago

What would it do if the file already exists with different permissions? Would it try to change the permissions on the existing file? If not, would it use the existing file's permissions on the new file when it rolls over, or would it use the configured permissions?

I think it's easier to just let the program code create the file with the permissions it prefers, and then lumberjack will respect those permissions. If you don't have a file created, lumberjack tries to use sensible defaults, but also obvious can't please everyone.

machine3 commented 2 years ago

Everything else remains the same, I just think this sensible defaults can be customized by the user instead of hard-coding it, which will be more flexible.

schmidtw commented 1 year ago

This would be nice to have. The PR appears pretty good. https://github.com/natefinch/lumberjack/pull/168

wbcustc commented 1 year ago

+1 on this PR

storskegg commented 1 year ago

+1 on this. It would be excellent to provide the desired octal perms vs touch a file in code, with the desired perms, if the file doesn't stat.

wreidlinger commented 8 months ago

Would also like to have this PR. https://github.com/natefinch/lumberjack/pull/168 Need to set custom file permission in caddy webserver logs and this is the library which is used for writing caddy logfiles. Many thanks!