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

Permission of log files (linux) #184

Closed
jukkahell opened this issue Oct 17, 2018 · 12 comments
Closed

Permission of log files (linux) #184

jukkahell opened this issue Oct 17, 2018 · 12 comments
Labels

Comments

@jukkahell
Copy link

Can we have something like this: winstonjs/winston#688
Would like to give group permission for the log files when created.

@mattberther
Copy link
Member

I've submitted a PR at rogerc/file-stream-rotator#46 to incorporate this functionality. If it is accepted, I'll publish an updated version of the transport with the requested functionality.

@mattberther
Copy link
Member

Added in 9770c46 and published to npm as winston-daily-rotate-file@3.4.0. Usage is documented in README, and similar to winston's FileTransport.

@jukkahell
Copy link
Author

Thanks a lot for the quick fix! Can you update index.d.ts as well :)

@mattberther
Copy link
Member

Added in b71d68a.

Sorry, but I dont use ts and am not familiar with how these defs work. Not sure if there's anything more that needs to happen, or if ts just uses the github repo.

@jukkahell
Copy link
Author

I believe this is good now. Thanks again!

@jukkahell
Copy link
Author

One more thing, can you release the new version to npm? :)

@mattberther
Copy link
Member

Published as winston-daily-rotate-file@3.4.1.

@parthgoyal
Copy link

Hi Matt,

I am using the "winston-daily-rotate-file": "3.9.0" version and encountered problem related to this issue.

Problem Statement:
I want to change the permissions of the log file that is created by winston on Windows as well as Linux. For that I have used the following transport:

var transport = new (transports.DailyRotateFile)({
filename: path.join(PATH , 'logGUI_%DATE%.log'),
datePattern: 'YYYYMMDD',
zippedArchive: false,
auditFile : LOGMETA_FILE,
maxFiles: 5,
options: {
mode: 0o666,
flags: 'a'
}
});

But the permissions of logfile did not change on both windows and Linux.
Please let me know how to change permission of winston logfile (Actually i want to give full permission to all the users and groups in both windows and linux. I got error whenever the same logfile access by different users for writing (at different point of time)

Thanks

@mattberther
Copy link
Member

What am I missing? The following code seems to work as expected. Do you have permission issues elsewhere on the filesystem?

var transport = new (winston.transports.DailyRotateFile)({
    filename: './logs/application-%DATE%',
    options: { flags: 'a', mode: 0o755 }
});

var logger = winston.createLogger({
    transports: [
        transport
    ]
});

logger.info("Hello world!");

Folder listing

$ ls -al logs
total 8
drwxr-xr-x   3 user  staff   96 Oct 29 18:26 .
drwxr-xr-x  19 user  staff  608 Oct 29 18:26 ..
-rwxr-xr-x   1 user  staff   42 Oct 29 18:26 application-2019-10-29

@parthgoyal
Copy link

Case 1
Default (no options)

logs# ls -ltr
total 12
-rw-r--r-- 1 root root 301 Oct 31 15:27 guiLogMeta
-rw-r--r-- 1 root root 6513 Oct 31 15:27 logGUI_20191031.log

Case 2
options: {
flags: 'a',
mode: 0o666
}

logs# ls -ltr
total 12
-rw-r--r-- 1 root root 301 Oct 31 15:19 guiLogMeta
-rw-r--r-- 1 root root 6513 Oct 31 15:19 logGUI_20191031.log

Case 3
options: {
flags: 'a',
mode: 0o755
}

logs# ls -ltr
total 16
-rw-r--r-- 1 root root 301 Oct 31 15:22 guiLogMeta
-rwxr-xr-x 1 root root 10137 Oct 31 15:22 logGUI_20191031.log

Case 4
options: {
flags: 'a',
mode: 0o777
}

logs# ls -ltr
total 20
-rw-r--r-- 1 root root 301 Oct 31 15:24 guiLogMeta
-rwxr-xr-x 1 root root 12867 Oct 31 15:24 logGUI_20191031.log

In any case, I did not get the write permissions for other users. Even in windows, I did not get write permissions for others users.

Please let me know if this is expected behaviour or it is bug or am I missing something

Thanks

@parthgoyal
Copy link

And What about auditFile ? How to change the auditFile permissions?

@mattberther
Copy link
Member

@parthgoyal If the mode is not set properly on a new file being created, there must be a misconfiguration in your node or system environment. The transport just passes the options hash through to fs.createWriteStream. Can you tell me if you see similar results from the following?

var fs = require('fs');

var stream = fs.createWriteStream('hello.txt', { mode: 0o777 });
stream.write('test');
stream.end();

At this time it is not possible to change auditFile permissions.

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

No branches or pull requests

3 participants