Skip to content

Commit

Permalink
Update logic to include loggers & also use default appender.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Oct 18, 2021
1 parent 9ee9b5a commit e96a2a7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
68 changes: 45 additions & 23 deletions src/core/server/config/deprecation/core_deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,30 +483,52 @@ describe('core deprecations', () => {
});

describe('using default pattern layout', () => {
it('warns when console appender is used', () => {
const { messages } = applyCoreDeprecations({
logging: {
root: {
appenders: ['default', 'console', '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.",
]
`);
});
['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.",
]
`);
});

it('does not warn when console appender is not used', () => {
const { messages } = applyCoreDeprecations({
logging: {
root: {
level: 'warn',
},
},
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.",
]
`);
});

it(`does not warn when ${appender} appender is not used in root`, () => {
const { messages } = applyCoreDeprecations({
logging: {
root: {
level: 'warn',
},
},
});
expect(messages).toMatchInlineSnapshot(`Array []`);
});
});
expect(messages).toMatchInlineSnapshot(`Array []`);
});

it('does not warn when console appender is overwritten', () => {
Expand All @@ -522,7 +544,7 @@ describe('core deprecations', () => {
},
},
root: {
appenders: ['default', 'console'],
appenders: ['console'],
},
},
});
Expand Down
11 changes: 9 additions & 2 deletions src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -598,9 +599,15 @@ const patternLayoutDefaultLoggingDeprecation: ConfigDeprecation = (
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 (
settings.logging?.root?.appenders?.includes('console') &&
settings.logging?.appenders?.console === undefined
(usesAppender('default') && settings.logging?.appenders?.default === undefined) ||
(usesAppender('console') && settings.logging?.appenders?.console === undefined)
) {
addDeprecation({
configPath: 'logging.root.appenders',
Expand Down

0 comments on commit e96a2a7

Please sign in to comment.