lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

Can support custom file permissions?

Open machine3 opened this issue 2 years ago • 10 comments

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

I want to replace 600 with 644

machine3 avatar Jul 20 '22 11:07 machine3

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.

natefinch avatar Jul 20 '22 14:07 natefinch

@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?

machine3 avatar Jul 21 '22 01:07 machine3

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.

natefinch avatar Jul 22 '22 19:07 natefinch

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

counten avatar Jul 31 '22 15:07 counten

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.

natefinch avatar Aug 01 '22 17:08 natefinch

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.

machine3 avatar Aug 02 '22 01:08 machine3

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

schmidtw avatar Mar 29 '23 22:03 schmidtw

+1 on this PR

wbcustc avatar Jun 29 '23 19:06 wbcustc

+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.

storskegg avatar Jul 05 '23 20:07 storskegg

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!

wreidlinger avatar Jan 31 '24 06:01 wreidlinger