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 daysToKeep not rolling by days #1035

Closed
wangduanduan opened this issue Aug 1, 2020 · 7 comments · Fixed by log4js-node/streamroller#78 or #1135
Closed

dateFile Appender daysToKeep not rolling by days #1035

wangduanduan opened this issue Aug 1, 2020 · 7 comments · Fixed by log4js-node/streamroller#78 or #1135
Milestone

Comments

@wangduanduan
Copy link

daysToKeep - integer (default 0) - if this value is greater than zero, then files older than that many days will be deleted during log rolling.

when the pattern is not .yyyy-MM-dd, the daysToKeep not work as doc says.

for example. when pattern is .yyyy-MM-dd-hh-mm, the daysToKeep is not control the old log Rolling by days, just keep the logs backups not more than daysToKeep.

log4js.configure({
    appenders: {
      well: {
        type: 'dateFile',
        filename: logFileName,
        pattern: '.yyyy-MM-dd-hh-mm',
        compress: true,
        daysToKeep: 3
      },
      console: { type: 'console' }
    },
    categories: {
      well: { appenders: [ 'well' ], level: 'debug'},
      default: {appenders: ['console'], level: 'debug'}
    }
})

log files

-rw-r--r--  1 dd  staff   855B Aug  1 14:59 well.log
-rw-r--r--  1 dd  staff   197B Aug  1 14:39 well.log.2020-08-01-14-38.gz
-rw-r--r--  1 dd  staff   323B Aug  1 14:45 well.log.2020-08-01-14-39.gz
-rw-r--r--  1 dd  staff   140B Aug  1 14:59 well.log.2020-08-01-14-45.gz
@beita1
Copy link

beita1 commented Oct 30, 2021

I also found this issue, do you have some new progress?

@lamweili
Copy link
Contributor

lamweili commented Jan 4, 2022

Related to #1080.

@beita1
Copy link

beita1 commented Jan 4, 2022 via email

@LmonZero
Copy link

LmonZero commented Mar 2, 2023

I want to split it both by day and by size, and I should

@lamweili
Copy link
Contributor

lamweili commented Mar 2, 2023

@LmonZero

I want to split it both by day and by size, and I should

Yes, you can. And it is either through file Appender or dateFile Appender.

File Appender

Note that, from version 4.x of log4js onwards, the file appender can take any of the options for the dateFile appender as well. So you could roll files by both date and size.
(source: https://log4js-node.github.io/log4js-node/file.html)

const log4js = require("log4js");
log4js.configure({
  appenders: {
    everything: {
      type: "file",
      filename: "testFile.log",
      pattern: "yyyy-MM-dd-hh", // settings from dateFile appender
      maxLogSize: 20
    },
  },
  categories: {
    default: { appenders: ["everything"], level: "debug" },
  },
});
const logger = log4js.getLogger();
logger.debug("hello world");

DateFile Appender

Note that, from version 4.x of log4js onwards, the file appender can take any of the options for the file appender as well. So you could roll files by both date and size.
(source: https://log4js-node.github.io/log4js-node/dateFile.html)

const log4js = require("log4js");
log4js.configure({
  appenders: {
    everything: {
      type: "dateFile",
      filename: "testDateFile.log",
      pattern: "yyyy-MM-dd-hh",
      maxLogSize: 20 // settings from file Appender
    },
  },
  categories: {
    default: { appenders: ["everything"], level: "debug" },
  },
});
var logger = log4js.getLogger();
logger.debug("hello world");

@lamweili
Copy link
Contributor

lamweili commented Mar 3, 2023

@LmonZero Does it resolve for you?

@LmonZero
Copy link

LmonZero commented Mar 8, 2023

yes

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