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

dateFile appender "mode" not working #1394

Open
sshhawwnn opened this issue Sep 7, 2023 · 4 comments
Open

dateFile appender "mode" not working #1394

sshhawwnn opened this issue Sep 7, 2023 · 4 comments

Comments

@sshhawwnn
Copy link

sshhawwnn commented Sep 7, 2023

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

lamweili commented Sep 8, 2023

Can I have more information?

  • log4js version?
  • Node.js version?
  • OS?

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

@sshhawwnn
Copy link
Author

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

default.txt permissions are same as info.txt

@lamweili
Copy link
Contributor

lamweili commented Sep 30, 2023

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

@sshhawwnn, any updates?

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

2 participants