From d623ad1bc034071dff43c4efb58a112084052807 Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Tue, 23 Jun 2020 12:58:16 -0600 Subject: [PATCH] Export config schema --- src/core/server/index.ts | 12 +++- .../server/logging/appenders/appenders.ts | 8 ++- src/core/server/logging/index.ts | 4 +- src/core/server/logging/logging_config.ts | 13 +++- src/core/server/server.api.md | 66 +++++++++++++++++++ 5 files changed, 99 insertions(+), 4 deletions(-) diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 6b5f4564f93de..e0afd5e57f041 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -62,7 +62,12 @@ import { CapabilitiesSetup, CapabilitiesStart } from './capabilities'; import { UuidServiceSetup } from './uuid'; import { MetricsServiceSetup } from './metrics'; import { StatusServiceSetup } from './status'; -import { LoggingServiceSetup } from './logging'; +import { + LoggingServiceSetup, + appendersSchema, + loggerContextConfigSchema, + loggerSchema, +} from './logging'; export { bootstrap } from './bootstrap'; export { Capabilities, CapabilitiesProvider, CapabilitiesSwitcher } from './capabilities'; @@ -463,4 +468,9 @@ export const config = { elasticsearch: { schema: elasticsearchConfigSchema, }, + logging: { + appenders: appendersSchema, + loggers: loggerSchema, + loggerContext: loggerContextConfigSchema, + }, }; diff --git a/src/core/server/logging/appenders/appenders.ts b/src/core/server/logging/appenders/appenders.ts index 6033b84dff204..3b90a10a1a76c 100644 --- a/src/core/server/logging/appenders/appenders.ts +++ b/src/core/server/logging/appenders/appenders.ts @@ -26,7 +26,13 @@ import { LogRecord } from '../log_record'; import { ConsoleAppender } from './console/console_appender'; import { FileAppender } from './file/file_appender'; -const appendersSchema = schema.oneOf([ +/** + * Config schema for validting the shape of the `appenders` key in in {@link LoggerContextConfigType} or + * {@link LoggingConfigType}. + * + * @public + */ +export const appendersSchema = schema.oneOf([ ConsoleAppender.configSchema, FileAppender.configSchema, LegacyAppender.configSchema, diff --git a/src/core/server/logging/index.ts b/src/core/server/logging/index.ts index 58f2016c6caaa..9471972030281 100644 --- a/src/core/server/logging/index.ts +++ b/src/core/server/logging/index.ts @@ -26,6 +26,8 @@ export { LoggingConfigType, LoggerContextConfigInput, LoggerConfigType, + loggerContextConfigSchema, + loggerSchema, } from './logging_config'; export { LoggingSystem, ILoggingSystem } from './logging_system'; export { @@ -33,4 +35,4 @@ export { LoggingServiceSetup, LoggingService, } from './logging_service'; -export { AppenderConfigType } from './appenders/appenders'; +export { appendersSchema, AppenderConfigType } from './appenders/appenders'; diff --git a/src/core/server/logging/logging_config.ts b/src/core/server/logging/logging_config.ts index f144b161f9c06..a6aafabeb970c 100644 --- a/src/core/server/logging/logging_config.ts +++ b/src/core/server/logging/logging_config.ts @@ -55,7 +55,12 @@ const levelSchema = schema.oneOf( } ); -const loggerSchema = schema.object({ +/** + * Config schema for validating the `loggers` key in {@link LoggerContextConfigType} or {@link LoggingConfigType}. + * + * @public + */ +export const loggerSchema = schema.object({ appenders: schema.arrayOf(schema.string(), { defaultValue: [] }), context: schema.string(), level: levelSchema, @@ -93,6 +98,12 @@ export const config = { export type LoggingConfigType = TypeOf; +/** + * Config schema for validating the inputs to the {@link LoggingServiceStart.configure} API. + * See {@link LoggerContextConfigType}. + * + * @public + */ export const loggerContextConfigSchema = schema.object({ appenders: schema.mapOf(schema.string(), Appenders.configSchema, { defaultValue: new Map(), diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 15751eac24007..4d6316fceb568 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -579,6 +579,72 @@ export const config: { ignoreVersionMismatch: import("@kbn/config-schema/target/types/types").ConditionalType; }>; }; + logging: { + appenders: import("@kbn/config-schema").Type | Readonly<{ + pattern?: string | undefined; + highlight?: boolean | undefined; + } & { + kind: "pattern"; + }>; + kind: "console"; + }> | Readonly<{} & { + path: string; + layout: Readonly<{} & { + kind: "json"; + }> | Readonly<{ + pattern?: string | undefined; + highlight?: boolean | undefined; + } & { + kind: "pattern"; + }>; + kind: "file"; + }> | Readonly<{ + legacyLoggingConfig?: any; + } & { + kind: "legacy-appender"; + }>>; + loggers: import("@kbn/config-schema").ObjectType<{ + appenders: import("@kbn/config-schema").Type; + context: import("@kbn/config-schema").Type; + level: import("@kbn/config-schema").Type; + }>; + loggerContext: import("@kbn/config-schema").ObjectType<{ + appenders: import("@kbn/config-schema").Type | Readonly<{ + pattern?: string | undefined; + highlight?: boolean | undefined; + } & { + kind: "pattern"; + }>; + kind: "console"; + }> | Readonly<{} & { + path: string; + layout: Readonly<{} & { + kind: "json"; + }> | Readonly<{ + pattern?: string | undefined; + highlight?: boolean | undefined; + } & { + kind: "pattern"; + }>; + kind: "file"; + }> | Readonly<{ + legacyLoggingConfig?: any; + } & { + kind: "legacy-appender"; + }>>>; + loggers: import("@kbn/config-schema").Type[]>; + }>; + }; }; // @public