zap icon indicating copy to clipboard operation
zap copied to clipboard

Can zap support dedicate file permission for log?

Open iamjackhu opened this issue 4 years ago • 4 comments

When set logpath for zap, it always to create with file mode 0644 for log file.

Does it support dedicate file permission mode, such as 0664?

iamjackhu avatar Aug 31 '20 08:08 iamjackhu

It's not possible to customize the permissions used for creating the file. However, this permission is only used if the file doesn't exist, so if you want a custom file permission, create the file beforehand with the permission you want, and then zap will use the existing file.

prashantv avatar Aug 31 '20 15:08 prashantv

It's not possible to customize the permissions used for creating the file. However, this permission is only used if the file doesn't exist, so if you want a custom file permission, create the file beforehand with the permission you want, and then zap will use the existing file.

So, this isn't quite right:

  • the typical way of customizing, especially in a scenario where one wants group write, is via umask
  • the correct thing for an application that doesn't care per-se about file permissions is to pass 0666 or 0777 to syscalls like os.OpenFile and os.Mkdir
  • the OS then applies umask and you end up with 0644 or 0755 typically
  • only security sensitive apps typically pass otherwise, and then it's things like 0700 or 0600 for something like a private key file
  • usually when you see os.OpenFile with 0644, the developer didn't actually care, and their intent was "standard / default behavior", which should have been 0666

jcorbin avatar Aug 31 '20 18:08 jcorbin

Sorry, I meant it's not possible to customize the permission value used by zap, it's hard-coded today and we don't have an easy way to customize it.

We can definitely change it to 0666 and rely on the umask.

prashantv avatar Aug 31 '20 18:08 prashantv

Also, look no further than os.Create for "what should the defaults be?" The only reason that zap doesn't uses os.Create is due to wanting append semantics rather than truncation, but it shouldn't be over-specifying the mode like this

jcorbin avatar Aug 31 '20 18:08 jcorbin