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

maxFiles is not working #368

Open
Codiving opened this issue Feb 10, 2023 · 11 comments
Open

maxFiles is not working #368

Codiving opened this issue Feb 10, 2023 · 11 comments

Comments

@Codiving
Copy link

Codiving commented Feb 10, 2023

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

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

@Codiving
Copy link
Author

I'm using the version below.

"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1"

@kirankuh
Copy link

kirankuh commented Apr 6, 2023

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

@gongshun
Copy link

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

@keitetran
Copy link

image
image

same problems. Maxfile not working....

@keitetran
Copy link

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

same problems ...

@jbeproxiad
Copy link

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

hyavari commented Dec 28, 2023

Same problem => version 4.7.1

@viniciusteixeiradias
Copy link

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

Miaamen commented Jun 26, 2024

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?

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

10 participants