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" ignored when "compress" is true #1043

Closed
ilsundal opened this issue Sep 3, 2020 · 3 comments · Fixed by log4js-node/streamroller#65 or #1135
Closed

dateFile appender "mode" ignored when "compress" is true #1043

ilsundal opened this issue Sep 3, 2020 · 3 comments · Fixed by log4js-node/streamroller#65 or #1135
Labels
dependencies Pull requests that update a dependency file
Milestone

Comments

@ilsundal
Copy link

ilsundal commented Sep 3, 2020

Log file r/w permissions (configured via "mode") are not set correctly when "compress" is set to "true".

How to reproduce:

  1. 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));

  1. 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.

  1. 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.

  1. 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).

@rnd-debug
Copy link
Contributor

rnd-debug commented Sep 5, 2020

@ilsundal @nomiddlename could reproduce. Need an update of the streamroller dependency: so I made a pull request for streamroller.

@ilsundal
Copy link
Author

ilsundal commented Sep 9, 2020

Excellent, thanks. Can you briefly tell me when / which version of log4js will include this fix?

@lamweili lamweili added this to the 6.4.0 milestone Jan 6, 2022
@lamweili lamweili added the dependencies Pull requests that update a dependency file label Jan 10, 2022
@lamweili
Copy link
Contributor

@ilsundal log4js@6.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
3 participants