diff --git a/x-pack/plugins/ml/server/client/log.js b/x-pack/plugins/ml/server/client/log.js deleted file mode 100644 index 0ef5e3f292ee..000000000000 --- a/x-pack/plugins/ml/server/client/log.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export let mlLog = () => {}; - -export function initMlServerLog(log) { - mlLog = (level, message) => log(['ml', level], message); -} diff --git a/x-pack/plugins/ml/server/client/log.ts b/x-pack/plugins/ml/server/client/log.ts new file mode 100644 index 000000000000..8ee5882f6c2c --- /dev/null +++ b/x-pack/plugins/ml/server/client/log.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Logger } from '../../../../../src/core/server'; + +export interface LogInitialization { + log: Logger; +} + +interface MlLog { + fatal: (message: string) => void; + error: (message: string) => void; + warn: (message: string) => void; + info: (message: string) => void; + debug: (message: string) => void; + trace: (message: string) => void; +} + +export let mlLog: MlLog; + +export function initMlServerLog(logInitialization: LogInitialization) { + mlLog = { + fatal: (message: string) => logInitialization.log.fatal(message), + error: (message: string) => logInitialization.log.error(message), + warn: (message: string) => logInitialization.log.warn(message), + info: (message: string) => logInitialization.log.info(message), + debug: (message: string) => logInitialization.log.debug(message), + trace: (message: string) => logInitialization.log.trace(message), + }; +} diff --git a/x-pack/plugins/ml/server/lib/check_annotations/index.js b/x-pack/plugins/ml/server/lib/check_annotations/index.js index efcd6ef54bde..6878ef6464aa 100644 --- a/x-pack/plugins/ml/server/lib/check_annotations/index.js +++ b/x-pack/plugins/ml/server/lib/check_annotations/index.js @@ -40,7 +40,7 @@ export async function isAnnotationsFeatureAvailable(callWithRequest) { if (!annotationsWriteAliasExists) return false; } catch (err) { - mlLog('info', 'Disabling ML annotations feature because the index/alias integrity check failed.'); + mlLog.info('Disabling ML annotations feature because the index/alias integrity check failed.'); return false; } diff --git a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js index 15b4e86ceafa..02128ae7ed5f 100644 --- a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js +++ b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js @@ -68,7 +68,7 @@ export class DataRecognizer { try { file = await this.readFile(`${this.modulesDir}/${dir}/manifest.json`); } catch (error) { - mlLog('warning', `Data recognizer skipping folder ${dir} as manifest.json cannot be read`); + mlLog.warn(`Data recognizer skipping folder ${dir} as manifest.json cannot be read`); } if (file !== undefined) { @@ -78,7 +78,7 @@ export class DataRecognizer { json: JSON.parse(file) }); } catch (error) { - mlLog('warning', `Data recognizer error parsing ${dir}/manifest.json. ${error}`); + mlLog.warn(`Data recognizer error parsing ${dir}/manifest.json. ${error}`); } } @@ -104,7 +104,7 @@ export class DataRecognizer { try { match = await this.searchForFields(moduleConfig, indexPattern); } catch (error) { - mlLog('warning', `Data recognizer error running query defined for module ${moduleConfig.id}. ${error}`); + mlLog.warn(`Data recognizer error running query defined for module ${moduleConfig.id}. ${error}`); } if (match === true) { @@ -194,7 +194,7 @@ export class DataRecognizer { config: JSON.parse(jobConfig) }); } catch (error) { - mlLog('warning', `Data recognizer error loading config for job ${job.id} for module ${id}. ${error}`); + mlLog.warn(`Data recognizer error loading config for job ${job.id} for module ${id}. ${error}`); } })); @@ -211,7 +211,7 @@ export class DataRecognizer { config }); } catch (error) { - mlLog('warning', `Data recognizer error loading config for datafeed ${datafeed.id} for module ${id}. ${error}`); + mlLog.warn(`Data recognizer error loading config for datafeed ${datafeed.id} for module ${id}. ${error}`); } })); @@ -232,7 +232,7 @@ export class DataRecognizer { config }); } catch (error) { - mlLog('warning', `Data recognizer error loading config for ${key} ${obj.id} for module ${id}. ${error}`); + mlLog.warn(`Data recognizer error loading config for ${key} ${obj.id} for module ${id}. ${error}`); } })); })); diff --git a/x-pack/plugins/ml/server/new_platform/plugin.ts b/x-pack/plugins/ml/server/new_platform/plugin.ts index 4644c86dff72..9cbe145804b7 100644 --- a/x-pack/plugins/ml/server/new_platform/plugin.ts +++ b/x-pack/plugins/ml/server/new_platform/plugin.ts @@ -57,7 +57,7 @@ import { jobAuditMessagesRoutes } from '../routes/job_audit_messages'; // @ts-ignore: could not find declaration file for module import { fileDataVisualizerRoutes } from '../routes/file_data_visualizer'; // @ts-ignore: could not find declaration file for module -import { initMlServerLog } from '../client/log'; +import { initMlServerLog, LogInitialization } from '../client/log'; export interface MlHttpServiceSetup extends HttpServiceSetup { route(route: ServerRoute | ServerRoute[]): void; @@ -108,9 +108,7 @@ export interface UsageInitialization { }; savedObjects: SavedObjectsService; } -export interface LogInitialization { - log: Logger; -} + export class Plugin { private readonly pluginId: string = 'ml'; private config: any; diff --git a/x-pack/plugins/ml/server/routes/system.js b/x-pack/plugins/ml/server/routes/system.js index 174921a0c98d..169cca1c99d1 100644 --- a/x-pack/plugins/ml/server/routes/system.js +++ b/x-pack/plugins/ml/server/routes/system.js @@ -54,9 +54,9 @@ export function systemRoutes({ commonRouteConfig, elasticsearchPlugin, route, xp // most likely they do not have the ml_user role and therefore will be blocked from using // ML at all. However, we need to catch this error so the privilege check doesn't fail. if (error.status === 403) { - mlLog('info', 'Unable to determine whether upgrade is being performed due to insufficient user privileges'); + mlLog.info('Unable to determine whether upgrade is being performed due to insufficient user privileges'); } else { - mlLog('warning', 'Unable to determine whether upgrade is being performed'); + mlLog.warn('Unable to determine whether upgrade is being performed'); } }