From 5de15fbe945f50201b5da65ce95628969ea292e6 Mon Sep 17 00:00:00 2001 From: Robert Rees Date: Tue, 10 Sep 2024 11:11:34 +0100 Subject: [PATCH] Switches to constructor-based logging injection --- __tests__/plugin.test.ts | 3 ++- src/plugin.ts | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/__tests__/plugin.test.ts b/__tests__/plugin.test.ts index b6069d7..37d6ada 100644 --- a/__tests__/plugin.test.ts +++ b/__tests__/plugin.test.ts @@ -11,6 +11,7 @@ import { } from './helpers/config' import { serverless } from './helpers/serverless' import { options } from './helpers/options' +import { mockLogging } from './helpers/logging' import { expectedPolicy } from './helpers/policy' import { expectedTarget, @@ -18,7 +19,7 @@ import { } from './helpers/target' import { ConcurrencyFunction } from 'src/@types' -const plugin = new Plugin(serverless) +const plugin = new Plugin(serverless, {}, mockLogging) describe('Validate', () => { it('should validate true', () => { diff --git a/src/plugin.ts b/src/plugin.ts index 10d6238..9e5d647 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -12,7 +12,7 @@ import { CustomMetricConfig, } from './@types' import { schema } from './schema/schema'; -import { log } from '@serverless/utils/log'; +import { Logging } from 'serverless/classes/Plugin' const text = { CLI_DONE: 'Added Provisioned Concurrency Auto Scaling to CloudFormation!', @@ -28,9 +28,13 @@ const text = { export default class Plugin { serverless: Serverless hooks: Record = {} + options: unknown + logging: Logging - constructor(serverless: Serverless) { + constructor(serverless: Serverless, options, logging: Logging) { this.serverless = serverless + this.options = options + this.logging = logging if ( this.serverless.configSchemaHandler && @@ -102,7 +106,7 @@ export default class Plugin { stage: this.serverless.getProvider('aws').getStage(), } - log.info(util.format(text.CLI_RESOURCE, config.function)) + this.logging.log.info(util.format(text.CLI_RESOURCE, config.function)) // eslint-disable-next-line @typescript-eslint/no-explicit-any const resources: any[] = [] @@ -191,11 +195,11 @@ export default class Plugin { try { const pcFunctions = this.getFunctions() this.validate(pcFunctions) - log.info(util.format(text.CLI_START)) + this.logging.log.info(util.format(text.CLI_START)) this.process(pcFunctions) - log.info(util.format(text.CLI_DONE)) + this.logging.log.info(util.format(text.CLI_DONE)) } catch (err) { - log.info(util.format(text.CLI_SKIP, err.message)) + this.logging.log.info(util.format(text.CLI_SKIP, err.message)) } } }