Skip to content

Commit

Permalink
add defaults for policy/strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Dec 10, 2020
1 parent fc190b9 commit bbb96f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/core/server/logging/appenders/rolling_file/policies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bbb96f4

Please sign in to comment.