diff --git a/src/core/server/config/deprecation/core_deprecations.test.ts b/src/core/server/config/deprecation/core_deprecations.test.ts index 223aae21dfd78..407295c8ab57f 100644 --- a/src/core/server/config/deprecation/core_deprecations.test.ts +++ b/src/core/server/config/deprecation/core_deprecations.test.ts @@ -481,4 +481,74 @@ describe('core deprecations', () => { `); }); }); + + describe('using default pattern layout', () => { + ['default', 'console'].forEach((appender) => { + describe(appender, () => { + it(`warns when ${appender} appender is used in root`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + appenders: [appender, 'test'], + }, + }, + }); + expect(messages).toMatchInlineSnapshot(` + Array [ + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0. For more info on ECS, see https://elastic.co/what-is/ecs.", + ] + `); + }); + + it(`warns when ${appender} appender is used in loggers`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + loggers: [ + { + name: 'my-logger', + appenders: [appender], + }, + ], + }, + }); + expect(messages).toMatchInlineSnapshot(` + Array [ + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0. For more info on ECS, see https://elastic.co/what-is/ecs.", + ] + `); + }); + + it(`does not warn when ${appender} appender is not used in root`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + level: 'warn', + }, + }, + }); + expect(messages).toMatchInlineSnapshot(`Array []`); + }); + }); + }); + + it('does not warn when console appender is overwritten', () => { + const { messages } = applyCoreDeprecations({ + logging: { + appenders: { + console: { + type: 'console', + layout: { + type: 'pattern', + pattern: 'testing', + }, + }, + }, + root: { + appenders: ['console'], + }, + }, + }); + expect(messages).toMatchInlineSnapshot(`Array []`); + }); + }); }); diff --git a/src/core/server/config/deprecation/core_deprecations.ts b/src/core/server/config/deprecation/core_deprecations.ts index 1cf67f479f9b3..fce0f6b0d9ecf 100644 --- a/src/core/server/config/deprecation/core_deprecations.ts +++ b/src/core/server/config/deprecation/core_deprecations.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { ConfigDeprecationProvider, ConfigDeprecation } from '@kbn/config'; +import { LoggingConfigType } from '../../logging'; const kibanaPathConf: ConfigDeprecation = (settings, fromPath, addDeprecation) => { if (process.env?.KIBANA_PATH_CONF) { @@ -592,6 +593,52 @@ const logFilterDeprecation: ConfigDeprecation = ( } }; +const patternLayoutDefaultLoggingDeprecation: ConfigDeprecation = ( + settings, + fromPath, + addDeprecation, + { branch } +) => { + const usesAppender = (name: string) => + settings.logging?.root?.appenders?.includes(name) || + settings.logging?.loggers?.some((logger: LoggingConfigType['loggers'][number]) => + logger.appenders?.includes(name) + ); + + if ( + (usesAppender('default') && settings.logging?.appenders?.default === undefined) || + (usesAppender('console') && settings.logging?.appenders?.console === undefined) + ) { + addDeprecation({ + configPath: 'logging.root.appenders', + level: 'warning', + documentationUrl: `https://github.com/elastic/kibana/blob/${branch}/src/core/server/logging/README.mdx#configuration`, + title: i18n.translate('core.deprecations.loggingPatternLayoutDefault.deprecationTitle', { + defaultMessage: `Kibana's default log format is changing to ECS JSON`, + }), + message: i18n.translate('core.deprecations.loggingPatternLayoutDefault.deprecationMessage', { + defaultMessage: + "It looks like you are using Kibana's built-in `console` appender, " + + 'which uses the "pattern" layout by default. In 8.0, the default layout ' + + 'will switch to JSON, which is ECS-compliant. If you are relying on the ' + + 'default pattern layout for log ingestion, be sure to explicitly configure this ' + + 'in your Kibana configuration to prevent any disruption when upgrading to 8.0. ' + + 'For more info on ECS, see https://elastic.co/what-is/ecs.', + }), + correctiveActions: { + manualSteps: [ + i18n.translate('core.deprecations.loggingPatternLayoutDefault.manualSteps1', { + defaultMessage: `[recommended] Update your log ingestion configuration to use ECS format.`, + }), + i18n.translate('core.deprecations.loggingPatternLayoutDefault.manualSteps2', { + defaultMessage: `Alternatively, you can preserve the existing format by configuring a custom appender with \`layout.type: 'pattern'\``, + }), + ], + }, + }); + } +}; + export const coreDeprecationProvider: ConfigDeprecationProvider = ({ unusedFromRoot, renameFromRoot, @@ -651,4 +698,5 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({ logEventsLogDeprecation, logEventsErrorDeprecation, logFilterDeprecation, + patternLayoutDefaultLoggingDeprecation, ];