parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

ParseServer maxLogFiles not yet effective ?

Open zurmokeeper opened this issue 2 years ago • 3 comments

New Issue Checklist

Issue Description

var api = new ParseServer({
    // logLevel:"error",
    databaseURI: database.uri,
    cloud: server.cloud,
    appId: server.appId,
    masterKey: server.masterKey,
    serverURL: Config.server.serverURL,
    directAccess: false,
    maxLogFiles: 5
});

maxLogFiles not yet effective ????

I specified the maximum number of log files as 5, but the number of generated files still exceeds 5, I read the configuration of winston, it is necessary to use with maxsize, in the exceeding of maxsize will automatically delete the log files before 5. But I read the source code of winston and parse-server configurations, and this maxLogFiles configuration is not correct to be used in winston in the end.

parse-server source code: 

const consoleFormat = options.json ? format.json() : format.simple();
const consoleOptions = Object.assign(
  {
    colorize: true,
    name: 'console',
    silent,
    format: format.combine(format.splat(), consoleFormat),
  },
  options
);

transports.push(new winston.transports.Console(consoleOptions));    // maxLogFiles ->maxFiles  This configuration winston is not for here.
}

logger.configure({
   transports,
});
winston  example: 

const logger = winston.createLogger();
logger.configure({
        level: 'verbose',
        transports: [
            new winston.transports.File({
                filename: path.join(__dirname, 'info.log'),
                // level: 'info',
                // maxsize: 1024,
                maxFiles: 2           //  It should be in the` File `configuration, not the` Console `configuration.
            })
        ]      
})

Steps to reproduce

Actual Outcome

Expected Outcome

Environment

Server

  • Parse Server version: v6.3.1
  • Operating system: windows

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 5.0

Logs

zurmokeeper avatar Nov 29 '23 03:11 zurmokeeper

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

Hello, I see this issue is still open. Can I give it a try?

vivekjoshi556 avatar Jun 29 '24 13:06 vivekjoshi556

@vivekjoshi556 Sure, please go ahead

mtrezza avatar Jun 29 '24 14:06 mtrezza

Hello @mtrezza & @zurmokeeper,

I was unable to reproduce the error. The rotation worked fine on my system. On the next day, the files rotated as expected. @zurmokeeper could you maybe provide more information if you are still facing the issue?

And you are right about Winston's documentation that maxSize is a required parameter but we are using winston-daily-rotate-file and there is nothing specified in the documentation about maxSize being required for maxFiles (from what I could understand, let me know if you find something else).

While checking it threw an error when I tried to use a value ending with a 'd' (e.g. '5d') for maxLogFiles (which is an acceptable value according to documentation in parse). This problem arises because maxLogFiles have action: parsers.objectParser in Definitions.js, which causes it to be parsed as an object, and since non-numeric characters in a string makes it an invalid JSON, the parsing fails.

According to documentation for maxLogFiles:

This can be a number of files or number of days. If using days, add 'd' as the suffix.

I don't think 'd' matters here anyway because both imply the same thing. For each day a new file is created, so how many log files should be created at max and how many days of files to keep is essentially the same thing, (so maybe we can update the documentation to remove instructions about this 'd')

vivekjoshi556 avatar Jul 07 '24 14:07 vivekjoshi556

Duplidate https://github.com/parse-community/parse-server/issues/6426

I looked into this years ago. The objectParser needs to be changed to numberStringParser.

dplewis avatar Jul 07 '24 14:07 dplewis

Closing as duplicate; added bounty to other issue since it's already open for 4 years.

mtrezza avatar Jul 07 '24 15:07 mtrezza