Add maxLogFiles option (#6296)

https://community.parseplatform.org/t/server-log-retention/867/2

Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null).

I'll run this in production for a few days. I assume it works.

Useful for saving disk space.

Update winston-daily-rotate-file package to 4.4.0
This commit is contained in:
Diamond Lewis
2019-12-24 11:35:28 -06:00
committed by GitHub
parent 49a0405e8f
commit 1a99cb3f2e
8 changed files with 59 additions and 57 deletions

View File

@@ -79,6 +79,7 @@ export function configureLogger({
logLevel = winston.level,
verbose = defaults.verbose,
silent = defaults.silent,
maxLogFiles,
} = {}) {
if (verbose) {
logLevel = 'verbose';
@@ -100,6 +101,7 @@ export function configureLogger({
options.dirname = logsFolder;
options.level = logLevel;
options.silent = silent;
options.maxFiles = maxLogFiles;
if (jsonLogs) {
options.json = true;

View File

@@ -76,10 +76,18 @@ export function getLoggerController(
logsFolder,
verbose,
logLevel,
maxLogFiles,
silent,
loggerAdapter,
} = options;
const loggerOptions = { jsonLogs, logsFolder, verbose, logLevel, silent };
const loggerOptions = {
jsonLogs,
logsFolder,
verbose,
logLevel,
silent,
maxLogFiles,
};
const loggerControllerAdapter = loadAdapter(
loggerAdapter,
WinstonLoggerAdapter,

View File

@@ -19,7 +19,7 @@ module.exports.ParseServerOptions = {
},
allowCustomObjectId: {
env: 'PARSE_SERVER_ALLOW_CUSTOM_OBJECT_ID',
help: 'Enable (or disable) custom objectId, defaults to false',
help: 'Enable (or disable) custom objectId',
action: parsers.booleanParser,
default: false,
},
@@ -230,6 +230,12 @@ module.exports.ParseServerOptions = {
help: 'Max value for limit option on queries, defaults to unlimited',
action: parsers.numberParser('maxLimit'),
},
maxLogFiles: {
env: 'PARSE_SERVER_MAX_LOG_FILES',
help:
"Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)",
action: parsers.objectParser,
},
maxUploadSize: {
env: 'PARSE_SERVER_MAX_UPLOAD_SIZE',
help: 'Max file size for uploads, defaults to 20mb',

View File

@@ -2,7 +2,7 @@
* @interface ParseServerOptions
* @property {Any} accountLockout account lockout policy for failed login attempts
* @property {Boolean} allowClientClassCreation Enable (or disable) client class creation, defaults to true
* @property {Boolean} allowCustomObjectId Enable (or disable) custom objectId, defaults to false
* @property {Boolean} allowCustomObjectId Enable (or disable) custom objectId
* @property {String[]} allowHeaders Add headers to Access-Control-Allow-Headers
* @property {Adapter<AnalyticsAdapter>} analyticsAdapter Adapter module for the analytics
* @property {String} appId Your Parse Application ID
@@ -42,6 +42,7 @@
* @property {String} masterKey Your Parse Master Key
* @property {String[]} masterKeyIps Restrict masterKey to be used by only these ips, defaults to [] (allow all ips)
* @property {Number} maxLimit Max value for limit option on queries, defaults to unlimited
* @property {Number|String} maxLogFiles Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)
* @property {String} maxUploadSize Max file size for uploads, defaults to 20mb
* @property {Union} middleware middleware for express server, can be string or function
* @property {Boolean} mountGraphQL Mounts the GraphQL endpoint

View File

@@ -10,6 +10,7 @@ import { WSSAdapter } from '../Adapters/WebSocketServer/WSSAdapter';
// @flow
type Adapter<T> = string | any | T;
type NumberOrBoolean = number | boolean;
type NumberOrString = number | string;
type ProtectedFields = any;
export interface ParseServerOptions {
@@ -51,6 +52,8 @@ export interface ParseServerOptions {
verbose: ?boolean;
/* Sets the level for logs */
logLevel: ?string;
/* Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null) */
maxLogFiles: ?NumberOrString;
/* Disables console output
:ENV: SILENT */
silent: ?boolean;