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

Improve logging pattern schema validation #200317

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { last } from 'lodash';
import { LogRecord } from '@kbn/logging';
import { Conversion } from './types';

const dateRegExp = /%date({(?<format>[^}]+)})?({(?<timezone>[^}]+)})?/g;
const dateRegExp = /%date(?:\{(?<format>[^}]+)\})?(?:\{(?<timezone>[A-Za-z/_+-]+)\})?/g;

const formats = {
ISO8601: 'ISO8601',
Expand All @@ -29,7 +29,6 @@ function formatDate(
): string {
const momentDate = moment(date);
momentDate.tz(timezone ?? moment.tz.guess());

switch (dateFormat) {
case formats.ISO8601:
return momentDate.toISOString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
const DEFAULT_PATTERN = `[%date][%level][%logger] %message`;

export const patternSchema = schema.string({
maxLength: 1000,
validate: (string) => {
DateConversion.validate!(string);
},
Expand Down