Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can support custom file permissions? #164

Open
machine3 opened this issue Jul 20, 2022 · 10 comments
Open

Can support custom file permissions? #164

machine3 opened this issue Jul 20, 2022 · 10 comments

Comments

@machine3
Copy link

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

I want to replace 600 with 644

@natefinch
Copy link
Owner

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
Copy link
Author

machine3 commented Jul 21, 2022

@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
Copy link
Owner

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
Copy link

counten commented Jul 31, 2022

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
Copy link
Owner

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
Copy link
Author

machine3 commented Aug 2, 2022

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.

counten added a commit to counten/lumberjack that referenced this issue Aug 3, 2022
counten added a commit to counten/lumberjack that referenced this issue Oct 3, 2022
jedisct1 added a commit to DNSCrypt/dnscrypt-proxy that referenced this issue Feb 25, 2023
@schmidtw
Copy link

This would be nice to have. The PR appears pretty good. #168

@wbcustc
Copy link

wbcustc commented Jun 29, 2023

+1 on this PR

@storskegg
Copy link

+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
Copy link

Would also like to have this PR. #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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants