From bbb96f4d2b45282b9b72dfe96882d98082f6a30f Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Thu, 10 Dec 2020 08:54:33 +0100 Subject: [PATCH] add defaults for policy/strategy --- .../appenders/rolling_file/policies/index.ts | 15 +++++++++++---- .../time_interval/time_interval_policy.ts | 2 +- .../rolling_file/rolling_file_context.ts | 6 +++--- .../appenders/rolling_file/strategies/index.ts | 10 +++++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/core/server/logging/appenders/rolling_file/policies/index.ts b/src/core/server/logging/appenders/rolling_file/policies/index.ts index 3604420a69597..66eb7f039d37b 100644 --- a/src/core/server/logging/appenders/rolling_file/policies/index.ts +++ b/src/core/server/logging/appenders/rolling_file/policies/index.ts @@ -18,6 +18,7 @@ */ import { schema } from '@kbn/config-schema'; +import moment from 'moment-timezone'; import { assertNever } from '@kbn/std'; import { TriggeringPolicy } from './policy'; import { RollingFileContext } from '../rolling_file_context'; @@ -43,10 +44,16 @@ export type TriggeringPolicyConfig = | SizeLimitTriggeringPolicyConfig | TimeIntervalTriggeringPolicyConfig; -export const triggeringPolicyConfigSchema = schema.oneOf([ - sizeLimitTriggeringPolicyConfigSchema, - timeIntervalTriggeringPolicyConfigSchema, -]); +const defaultPolicy: TimeIntervalTriggeringPolicyConfig = { + kind: 'time-interval', + interval: moment.duration(24, 'hour'), + modulate: true, +}; + +export const triggeringPolicyConfigSchema = schema.oneOf( + [sizeLimitTriggeringPolicyConfigSchema, timeIntervalTriggeringPolicyConfigSchema], + { defaultValue: defaultPolicy } +); export const createTriggeringPolicy = ( config: TriggeringPolicyConfig, diff --git a/src/core/server/logging/appenders/rolling_file/policies/time_interval/time_interval_policy.ts b/src/core/server/logging/appenders/rolling_file/policies/time_interval/time_interval_policy.ts index 352e124875845..330a74b03f20e 100644 --- a/src/core/server/logging/appenders/rolling_file/policies/time_interval/time_interval_policy.ts +++ b/src/core/server/logging/appenders/rolling_file/policies/time_interval/time_interval_policy.ts @@ -54,7 +54,7 @@ export const timeIntervalTriggeringPolicyConfigSchema = schema.object({ defaultValue: '24h', validate: (interval) => { if (!isValidRolloverInterval(interval)) { - return 'Interval value cannot overflow to a higher field.'; + return 'Interval value cannot overflow to a higher time unit.'; } }, }), diff --git a/src/core/server/logging/appenders/rolling_file/rolling_file_context.ts b/src/core/server/logging/appenders/rolling_file/rolling_file_context.ts index 376878ab55cc6..ed3b30cea2330 100644 --- a/src/core/server/logging/appenders/rolling_file/rolling_file_context.ts +++ b/src/core/server/logging/appenders/rolling_file/rolling_file_context.ts @@ -39,12 +39,12 @@ export class RollingFileContext { this.currentFileTime = birthtime.getTime(); this.currentFileSize = size; } catch (e) { - this.currentFileTime = Date.now(); - this.currentFileSize = 0; if (e.code !== 'ENOENT') { // eslint-disable-next-line no-console - console.log('[RollingFileAppender] error accessing the log file', e); + console.error('[RollingFileAppender] error accessing the log file', e); } + this.currentFileTime = Date.now(); + this.currentFileSize = 0; } } } diff --git a/src/core/server/logging/appenders/rolling_file/strategies/index.ts b/src/core/server/logging/appenders/rolling_file/strategies/index.ts index 7668daf05345b..e51a16a0026a8 100644 --- a/src/core/server/logging/appenders/rolling_file/strategies/index.ts +++ b/src/core/server/logging/appenders/rolling_file/strategies/index.ts @@ -29,7 +29,15 @@ import { RollingFileContext } from '../rolling_file_context'; export { RollingStrategy } from './strategy'; export type RollingStrategyConfig = NumericRollingStrategyConfig; -export const rollingStrategyConfigSchema = schema.oneOf([numericRollingStrategyConfigSchema]); +const defaultStrategy: NumericRollingStrategyConfig = { + kind: 'numeric', + pattern: '-%i', + max: 7, +}; + +export const rollingStrategyConfigSchema = schema.oneOf([numericRollingStrategyConfigSchema], { + defaultValue: defaultStrategy, +}); export const createRollingStrategy = ( config: RollingStrategyConfig,