Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging: switch to injected logger #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ 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,
expectedTargetWithSingleScheduledAction,
} 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', () => {
Expand Down
16 changes: 10 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
Expand All @@ -28,9 +28,13 @@ const text = {
export default class Plugin {
serverless: Serverless
hooks: Record<string, unknown> = {}
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 &&
Expand Down Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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))
}
}
}