-
Notifications
You must be signed in to change notification settings - Fork 764
Description
Log file r/w permissions (configured via "mode") are not set correctly when "compress" is set to "true".
How to reproduce:
- Create "index.js" with this code:
'use strict';
const log4js = require('log4js');
// default log4js configuration: log everything to the console
const LOG4JS_CONFIGURATION_DEFAULT =
{
"appenders": {
"console": {
"type": "console"
},
"file": {
"type": "dateFile",
"filename": "my-logger.log",
"pattern": ".yyyy-MM-dd",
"mode": 384,
"mode-comment": "mode 384 is the decimal value of octal 0600",
"daysToKeep": 30,
"compress": true
}
},
"categories": {
"default": {
"appenders": ["console", "file"],
"level": "trace"
}
}
};
// apply default configuration
log4js.configure(LOG4JS_CONFIGURATION_DEFAULT);
async function main() {
let logger = log4js.getLogger('my-logger');
logger.info('some log');
await log4js.shutdown();
}
main()
.catch((err) => console.error(err));
- Run
$ node index.js
and then
$ ls -l
to get
-rw------- 1 morten morten 54 Sep 3 14:23 my-logger.log
Note the "-rw-------" part, which means read/write only for me ("morten"). That matches my mode config in the code, so all good.
- Run
$ touch -d "24 hours ago" my-logger.log
to change the file date back 24 hours (to force compression in step 4 below).
and then
$ ls -l
to get
-rw------- 1 morten morten 54 Sep 2 14:26 my-logger.log
Note that "Sep 3" changed to "Sep 2" as expected so all good.
- Run
$ node index.js
and then
$ ls -l
to get
-rw------- 1 morten morten 54 Sep 3 14:28 my-logger.log
-rw-r--r-- 1 morten morten 72 Sep 3 14:28 my-logger.log.2020-09-02.gz
Note how the compressed file has "-rw-r--r--" file permisions, and not "-rw-------" as expected. Thus, "mode" config is apparently ignored when "compress" is "true" in the log4js config. (If I set "compress" to "false" then the backup file has the expected "-rw-------" file permissions).
I am using log4js version 6.3.0 (the newest one).