winstonjs / winston-daily-rotate-file

A transport for winston which logs to a rotating file each day.
MIT License
889 stars 151 forks source link

maxFiles is not working #368

Open Codiving opened 1 year ago

Codiving commented 1 year ago

I want a log file to be created every day. And I want to set the maximum number to 2. I have written code like below.

const fileConsole = new winston.transports.DailyRotateFile({
  filename: "%DATE%.log",
  datePattern: "YYYY-MM-DD",
  zippedArchive: true,
  dirname: "logs",
  frequency: "1d",
  maxFiles: 2
});

const devConsole = new winston.transports.Console({
  format: winston.format.combine(
    winston.format.splat(),
    winston.format.colorize()
  )
});

const logger = winston.createLogger({
  format: combine(
    timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
    printf(info => {
      return `${info.timestamp} ${info.level}: ${info.message}`;
    })
  ),
  transports: [devConsole, fileConsole]
});

But, It's not working well. However, the log files are not being deleted as shown in the image below.

스크린샷 2023-02-10 오전 11 35 28

Is there any problem with my code? Thanks in advance for any help.

Vishal8523 commented 1 year ago

Facing the same issue with Winston 2 and Winston-daily-file-rotate 3 Any inputs on this ?

Codiving commented 1 year ago

I'm using the version below.

"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1"
kirankuh commented 1 year ago

It should be like this --> maxFiles: '2d' Please check docs - https://www.npmjs.com/package/winston-daily-rotate-file

gongshun commented 1 year ago

Check out how many audit.json files are in your log directory, if there are more than one, it means your configuration problem

keitetran commented 1 year ago

image image

same problems. Maxfile not working....

keitetran commented 1 year ago

Look like file will delete on this list new setting will generate new audit file, it not includes old file. Delete all file befor change log setting.

image

CherishLyf commented 1 year ago

same problems ...

jbeproxiad commented 11 months ago

Same here with

"dependencies": {
    [...]
    "winston": "3.10.0",
    "winston-daily-rotate-file": "4.7.1"
  },

The usage of maxFiles with a value in days like maxFiles: '7d' looks broken : no new file is created. Updates appreciated

hyavari commented 8 months ago

Same problem => version 4.7.1

viniciusteixeiradias commented 7 months ago

@Codiving I think the problem you're having is because of this line: frequency: "1d". When you look at the documentation, you'll see that only "#m" or "#h" are allowed. So, you need to change your code to frequency: "24h" to make it work correctly.

Miaamen commented 2 months ago

same problems. Maxfile not working.... { "keep": { "days": true, "amount": 8 }, "auditLog": "/xx-audit.json", "files": [ { "date": 1718692539733, "name": "/xx/info-2024-06-18.log", "hash": "7ed5010ad75751bd9adf20403331a51060feef47b4d30290219e95992a2eac91" }, { "date": 1718726400005, "name": "/xx/info-2024-06-19.log", "hash": "708f6c151c554ead283234aa78e515c5edfb51d6545da1a9fdc7bc27e3c4f2f0" }, { "date": 1718812800006, "name": "/xx/info-2024-06-20.log", "hash": "9bc88a236a545548c41c68444f9ab18bab571161ab96168a034b49eeeb9c1c91" }, { "date": 1718899200006, "name": "/xx/info-2024-06-21.log", "hash": "b170cc49621c0e48f9354af4294ae3288cda0b7415cefcf7733f2242c978cd9c" }, { "date": 1718985600006, "name": "/xx/info-2024-06-22.log", "hash": "ecefffb54add0a73d0a3a3a5be675336d80698f52b4a1042e2732bcdf87d034a" }, { "date": 1719072000005, "name": "/xx/info-2024-06-23.log", "hash": "03e981f15d6af7f1eebb0943495daab5cd0d5c0ab1788927e71cc2d2cb1e797d" }, { "date": 1719158400005, "name": "/xx/info-2024-06-24.log", "hash": "cb926e49263b8f1a14c8c76c876368c89c792acc0f5bac85df957d0cd107f5e7" }, { "date": 1719244800006, "name": "/xx/info-2024-06-25.log", "hash": "8c221a0f1d234bd3320693dc40fd8a55a24a910122240c9fb34f357278314255" }, { "date": 1719331200005, "name": "/xx/info-2024-06-26.log", "hash": "6b61efd9e28472ed6ce4d04b26fa5cba09d79ede4b35ee0f87637069730d4c81" } ], "hashType": "sha256" } Does anyone know how to fix this?