lumberjack
lumberjack copied to clipboard
Can support custom file permissions?
https://github.com/natefinch/lumberjack/blob/v3/lumberjack.go#L255
I want to replace 600 with 644
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 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?
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.
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
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.
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.
This would be nice to have. The PR appears pretty good. https://github.com/natefinch/lumberjack/pull/168
+1 on this PR
+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.
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!