log4js-node / log4js-node

A port of log4js to node.js
https://log4js-node.github.io/log4js-node/
Other
5.79k stars 774 forks source link

dateFile appender "mode" not working #1394

Open sshhawwnn opened 1 year ago

sshhawwnn commented 1 year ago
const CONFIG = {
  appenders: {
    out: { type: 'console' },
    info: {
      type: 'dateFile',
      filename: 'logs/info/info.txt',
      alwaysIncludePattern: true,
      keepFileExt: true,
      numBackups: BACKUP_VAL,
      maxLogSize: MAXSIZE_VAL,
      mode: 384
    },
    default: {
      type: 'dateFile',
      filename: 'logs/default/default.txt',
      alwaysIncludePattern: true,
      keepFileExt: true,
      numBackups: BACKUP_VAL,
      maxLogSize: MAXSIZE_VAL,
      mode: 384
    }
  },
  categories: {
    info: { appenders: ['info'], level: 'info' },
    default: { appenders: ['out', 'default'], level: 'info' },
  }
};
log4js.configure(CONFIG);

Tried with both mode: 384 or mode: 0o644, none is working.

image

lamweili commented 1 year ago

Can I have more information?

Also, how about the default.txt? Is it the same as the info.txt screenshot?

sshhawwnn commented 1 year ago

Log4js: 6.9.1 Node.js: 20.6 Running on Docker.

default.txt permissions are same as info.txt

lamweili commented 11 months ago

Tried with both mode: 384 or mode: 0o644, none is working.

image

Hi, based on your code, which uses mode: 384, it works as intended. 384 -> 0o600 -> -rw-------, validated by your screenshot.

If you want 0o644 (-rw-r--r--), you can use either mode: 420 or mode: 0o644.

Also, if the file is an existing file, it will retain the existing permissions and permissions specified in the log4js configuration will not take effect. So, please make sure you delete the file for a clean test.

You might also want to check the umask of the environment, as it will mask the supplied mode configuration.


const log4js = require('log4js');

const BACKUP_VAL = 3;
const MAXSIZE_VAL = 1048576;

const CONFIG = {
  appenders: {
    out: { type: 'console' },
    info: {
      type: 'dateFile',
      filename: 'logs/info.txt',
      alwaysIncludePattern: true,
      keepFileExt: true,
      numBackups: BACKUP_VAL,
      maxLogSize: MAXSIZE_VAL,
      mode: 0o600
    },
    default: {
      type: 'dateFile',
      filename: 'logs/default.txt',
      alwaysIncludePattern: true,
      keepFileExt: true,
      numBackups: BACKUP_VAL,
      maxLogSize: MAXSIZE_VAL,
      mode: 0o644
    }
  },
  categories: {
    info: { appenders: ['info'], level: 'info' },
    default: { appenders: ['out', 'default'], level: 'info' },
  }
};
log4js.configure(CONFIG);

const loginfo = log4js.getLogger("info"); 
const logothers = log4js.getLogger("others");

loginfo.info("test"); 
logothers.info("test"); 
info.txt    is 0o600 or 384 or -rw-------
default.txt is 0o644 or 420 or -rw-r--r--
lamweili commented 9 months ago

@sshhawwnn, any updates?