From f04ef962d585db0c9b5261dab0f97e7f4f079190 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 7 Feb 2022 11:36:31 -0800 Subject: [PATCH 1/7] Use ES modudle directly as handler --- handlers/blue.js | 28 ++++++++++++++++++++++------ handlers/blue.mjs | 25 ------------------------- handlers/package.json | 1 - handlers/red.js | 38 ++++++++++++++++++++++++++++++++------ handlers/red.mjs | 35 ----------------------------------- test/handlers/blue.spec.js | 2 +- test/handlers/red.spec.js | 2 +- 7 files changed, 56 insertions(+), 75 deletions(-) delete mode 100644 handlers/blue.mjs delete mode 100644 handlers/package.json delete mode 100644 handlers/red.mjs diff --git a/handlers/blue.js b/handlers/blue.js index 25cbed8..613343c 100644 --- a/handlers/blue.js +++ b/handlers/blue.js @@ -1,12 +1,28 @@ -'use strict' +import Sentry from '@sentry/serverless' +import { asValue } from 'awilix' +import { envString } from '@pureskillgg/ace' -const Sentry = require('@sentry/serverless') +import { invokeHandler } from '../index.js' Sentry.AWSLambda.init() -const index = import('./blue.mjs') +const registerDependencies = (container, config) => { + container.register({ rank: asValue(config.rank) }) +} -exports.handler = Sentry.AWSLambda.wrapHandler(async (...args) => { - const { handler } = await index - return handler(...args) +const parameters = { + rank: envString('RANK') +} + +const createProcessor = + ({ rank }) => + async (event, ctx) => { + return { ...event, rank } + } + +export const createHandler = invokeHandler({ + registerDependencies, + createProcessor }) + +export const handler = Sentry.AWSLambda.wrapHandler(createHandler(parameters)) diff --git a/handlers/blue.mjs b/handlers/blue.mjs deleted file mode 100644 index a0c3bfd..0000000 --- a/handlers/blue.mjs +++ /dev/null @@ -1,25 +0,0 @@ -import { asValue } from 'awilix' -import { envString } from '@pureskillgg/ace' - -import { invokeHandler } from '../index.js' - -const registerDependencies = (container, config) => { - container.register({ rank: asValue(config.rank) }) -} - -const parameters = { - rank: envString('RANK') -} - -const createProcessor = - ({ rank }) => - async (event, ctx) => { - return { ...event, rank } - } - -export const createHandler = invokeHandler({ - registerDependencies, - createProcessor -}) - -export const handler = createHandler(parameters) diff --git a/handlers/package.json b/handlers/package.json deleted file mode 100644 index 0967ef4..0000000 --- a/handlers/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/handlers/red.js b/handlers/red.js index 7139fde..89e169c 100644 --- a/handlers/red.js +++ b/handlers/red.js @@ -1,12 +1,38 @@ -'use strict' +import Sentry from '@sentry/serverless' +import { asClass } from 'awilix' +import { LambdaClient } from '@pureskillgg/awsjs' +import { ssmString } from '@pureskillgg/ace' -const Sentry = require('@sentry/serverless') +import { invokeHandler } from '../index.js' Sentry.AWSLambda.init() -const index = import('./red.mjs') +const parameters = { + blueLambdaFunction: ssmString('BLUE_LAMBDA_FUNCTION_SSM_PATH') +} -exports.handler = Sentry.AWSLambda.wrapHandler(async (...args) => { - const { handler } = await index - return handler(...args) +const createProcessor = + ({ blueLambdaClient, log }) => + async (event, ctx) => { + return blueLambdaClient.invokeJson(event) + } + +const registerDependencies = (container, config) => { + container.register( + 'blueLambdaClient', + asClass(LambdaClient).inject(() => ({ + name: 'blue', + functionName: config.blueLambdaFunction, + AwsLambdaClient: undefined, + params: undefined + })) + ) +} + +export const createHandler = invokeHandler({ + parameters, + createProcessor, + registerDependencies }) + +export const handler = Sentry.AWSLambda.wrapHandler(createHandler(parameters)) diff --git a/handlers/red.mjs b/handlers/red.mjs deleted file mode 100644 index 98077bd..0000000 --- a/handlers/red.mjs +++ /dev/null @@ -1,35 +0,0 @@ -import { asClass } from 'awilix' -import { LambdaClient } from '@pureskillgg/awsjs' -import { ssmString } from '@pureskillgg/ace' - -import { invokeHandler } from '../index.js' - -const parameters = { - blueLambdaFunction: ssmString('BLUE_LAMBDA_FUNCTION_SSM_PATH') -} - -const createProcessor = - ({ blueLambdaClient, log }) => - async (event, ctx) => { - return blueLambdaClient.invokeJson(event) - } - -const registerDependencies = (container, config) => { - container.register( - 'blueLambdaClient', - asClass(LambdaClient).inject(() => ({ - name: 'blue', - functionName: config.blueLambdaFunction, - AwsLambdaClient: undefined, - params: undefined - })) - ) -} - -export const createHandler = invokeHandler({ - parameters, - createProcessor, - registerDependencies -}) - -export const handler = createHandler(parameters) diff --git a/test/handlers/blue.spec.js b/test/handlers/blue.spec.js index c7cba5c..0a53cc9 100644 --- a/test/handlers/blue.spec.js +++ b/test/handlers/blue.spec.js @@ -1,7 +1,7 @@ import test from 'ava' import { localString } from '@pureskillgg/ace' -import { createHandler } from '../../handlers/blue.mjs' +import { createHandler } from '../../handlers/blue.js' test('invoke', async (t) => { const event = { foo: 'bar' } diff --git a/test/handlers/red.spec.js b/test/handlers/red.spec.js index f4a6298..544b8b6 100644 --- a/test/handlers/red.spec.js +++ b/test/handlers/red.spec.js @@ -1,7 +1,7 @@ import test from 'ava' import { asValue } from 'awilix' -import { createHandler } from '../../handlers/red.mjs' +import { createHandler } from '../../handlers/red.js' test('invoke', async (t) => { const event = { foo: 'bar' } From 005819301f404f9938a68ec4ce6faffb9b99fb8b Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 7 Feb 2022 11:53:56 -0800 Subject: [PATCH 2/7] Load config at handler creation --- README.md | 12 ++++++------ handlers/blue.js | 4 +++- handlers/red.js | 4 +++- lib/config.js | 18 ++++++++---------- lib/ctx.js | 4 ++++ lib/handlers/factory.js | 16 ++++++++++------ test/handlers/blue.spec.js | 2 +- test/handlers/http.spec.js | 12 ++++++------ test/handlers/red.spec.js | 2 +- test/handlers/sqs.spec.js | 4 ++-- 10 files changed, 44 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 295209d..7c5226b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ export const createHandler = invokeHandler({ registerDependencies }) -export const handler = createHandler(parameters) +export const handler = await createHandler(parameters) ``` ## Installation @@ -76,7 +76,7 @@ A trivial handler that does nothing may be created like this import { invokeHandler } from '@pureskillgg/glhf' const createHandler = invokeHandler() -export const handler = createHandler() +export const handler = await createHandler() ``` To create a more useful handler, leverage @@ -86,7 +86,7 @@ To create a more useful handler, leverage import { invokeHandler } from '@pureskillgg/glhf' const createHandler = invokeHandler({ createProcessor, registerDependencies }) -export const handler = createHandler(parameters) +export const handler = await createHandler(parameters) ``` - Use `parameters` to load configuration with [AWS Config Executor]. @@ -142,7 +142,7 @@ const createProcessor = () => async (event, ctx) => { const createHandler = invokeHandler({ createProcessor }) -export const handler = createHandler() +export const handler = await createHandler() ``` #### EventBridge Handler @@ -181,7 +181,7 @@ const createProcessor = () => async (event, ctx) => { const createHandler = invokeHandler({ createProcessor }) -export const handler = createHandler() +export const handler = await createHandler() ``` ```yaml @@ -239,7 +239,7 @@ const createProcessor = () => async (event, ctx) => { const createHandler = sqsJsonHandler({ createProcessor }) -export const handler = createHandler() +export const handler = await createHandler() ``` ### Advanced usage diff --git a/handlers/blue.js b/handlers/blue.js index 613343c..834c7cb 100644 --- a/handlers/blue.js +++ b/handlers/blue.js @@ -25,4 +25,6 @@ export const createHandler = invokeHandler({ createProcessor }) -export const handler = Sentry.AWSLambda.wrapHandler(createHandler(parameters)) +export const handler = Sentry.AWSLambda.wrapHandler( + await createHandler(parameters) +) diff --git a/handlers/red.js b/handlers/red.js index 89e169c..75673de 100644 --- a/handlers/red.js +++ b/handlers/red.js @@ -35,4 +35,6 @@ export const createHandler = invokeHandler({ registerDependencies }) -export const handler = Sentry.AWSLambda.wrapHandler(createHandler(parameters)) +export const handler = Sentry.AWSLambda.wrapHandler( + await createHandler(parameters) +) diff --git a/lib/config.js b/lib/config.js index 887da12..73b7b1d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,11 +1,9 @@ -import { getConfig } from '@pureskillgg/ace' +import { getConfig as getAceConfig } from '@pureskillgg/ace' -export const createGetConfig = - ({ parameters, cache, aliases }) => - async (ctx, log) => - getConfig({ - parameters, - cache, - aliases, - log: log.child({ isConfigLog: true }) - }) +export const getConfig = async ({ parameters, cache, aliases, log }) => + getAceConfig({ + parameters, + cache, + aliases, + log: log.child({ isConfigLog: true }) + }) diff --git a/lib/ctx.js b/lib/ctx.js index 49922d7..26a6e1a 100644 --- a/lib/ctx.js +++ b/lib/ctx.js @@ -15,3 +15,7 @@ export const createCtx = (event, context) => { reqId } } + +export const createGlobalCtx = (env) => ({ + functionName: env.AWS_LAMBDA_FUNCTION_NAME +}) diff --git a/lib/handlers/factory.js b/lib/handlers/factory.js index d7a4c60..419d50c 100644 --- a/lib/handlers/factory.js +++ b/lib/handlers/factory.js @@ -5,8 +5,10 @@ import { createInvokeWrapper } from '../wrappers/index.js' import { createEventStrategy } from '../strategies/index.js' import { createContainer, createScope } from '../container.js' import { createCache } from '../cache.js' -import { createGetConfig } from '../config.js' -import { createCtx } from '../ctx.js' +import { getConfig } from '../config.js' +import { createCtx, createGlobalCtx } from '../ctx.js' + +const env = { ...process.env } export const createHandler = ({ @@ -18,21 +20,23 @@ export const createHandler = createStrategy = createEventStrategy, logOptions = {} }) => - (parameters, t, overrideDependencies = registerEmptyDependencies) => { + async (parameters, t, overrideDependencies = registerEmptyDependencies) => { const cache = createCache() const container = createContainer() - const getConfig = createGetConfig({ + if (process.env.NODE_ENV === 'test' && !t) return async () => {} + + const config = await getConfig({ parameters, cache, - aliases: t ? undefined : { ...process.env } + aliases: t ? undefined : env, + log: createLogger(createGlobalCtx(env), t) }) return async (event, context = {}) => { try { const ctx = createCtx(event, context) const log = createLogger(ctx, t, logOptions) - const config = await getConfig(ctx, log) registerDependencies(container, config) overrideDependencies(container, config) diff --git a/test/handlers/blue.spec.js b/test/handlers/blue.spec.js index 0a53cc9..6dc3817 100644 --- a/test/handlers/blue.spec.js +++ b/test/handlers/blue.spec.js @@ -5,7 +5,7 @@ import { createHandler } from '../../handlers/blue.js' test('invoke', async (t) => { const event = { foo: 'bar' } - const handler = createHandler(parameters, t) + const handler = await createHandler(parameters, t) const data = await handler(event) t.snapshot(data, 'handler') }) diff --git a/test/handlers/http.spec.js b/test/handlers/http.spec.js index 51c5702..f0c93e0 100644 --- a/test/handlers/http.spec.js +++ b/test/handlers/http.spec.js @@ -7,7 +7,7 @@ test('httpHandler: invoke', async (t) => { const event = await readJson('fixtures', 'event', 'api-gateway-proxy.json') event.reqId = 'mock-req-id' const createHandler = httpHandler({ createProcessor }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -18,7 +18,7 @@ test('httpHandler: handle error', async (t) => { const createHandler = httpHandler({ createProcessor: createProcessorWithError }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -29,7 +29,7 @@ test('httpHandler: handle boom error', async (t) => { const createHandler = httpHandler({ createProcessor: createProcessorWithBoomError }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -39,7 +39,7 @@ test('httpJsonHandler: invoke', async (t) => { event.reqId = 'mock-req-id' event.body = '{"a":1}' const createHandler = httpJsonHandler({ createProcessor }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -51,7 +51,7 @@ test('httpJsonHandler: handle error', async (t) => { const createHandler = httpHandler({ createProcessor: createProcessorWithError }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -63,7 +63,7 @@ test('httpJsonHandler: handle boom error', async (t) => { const createHandler = httpJsonHandler({ createProcessor: createProcessorWithBoomError }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) diff --git a/test/handlers/red.spec.js b/test/handlers/red.spec.js index 544b8b6..eb0e48a 100644 --- a/test/handlers/red.spec.js +++ b/test/handlers/red.spec.js @@ -17,7 +17,7 @@ test('invoke', async (t) => { container.register('blueLambdaClient', asValue(blueLambdaClient)) } - const handler = createHandler({}, t, overrideDependencies) + const handler = await createHandler({}, t, overrideDependencies) const data = await handler(event) t.snapshot(data, 'handler') }) diff --git a/test/handlers/sqs.spec.js b/test/handlers/sqs.spec.js index 5f8943b..dcb2d6c 100644 --- a/test/handlers/sqs.spec.js +++ b/test/handlers/sqs.spec.js @@ -6,7 +6,7 @@ test('sqsHandler: invoke', async (t) => { const event = await readJson('fixtures', 'event', 'sqs.json') event.reqId = 'mock-req-id' const createHandler = sqsHandler({ createProcessor }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) @@ -15,7 +15,7 @@ test('sqsJsonHandler: invoke', async (t) => { const event = await readJson('fixtures', 'event', 'sqs.json') event.reqId = 'mock-req-id' const createHandler = sqsJsonHandler({ createProcessor }) - const handler = createHandler({}, t) + const handler = await createHandler({}, t) const data = await handler(event) t.snapshot(data, 'handler') }) From cb988cf109c46c82790752b231d8d05d03dd3b84 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Wed, 16 Mar 2022 11:27:04 -0700 Subject: [PATCH 3/7] Stub t log if no log --- README.md | 3 +++ lib/logger.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c5226b..336b7b9 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,9 @@ export const handler = await createHandler(parameters) All exported handler functions return a new handler factory with identical signature: 1. `parameters`: The [AWS Config Executor] parameters to load. 2. `t`: The AVA `t` object (if running inside AVA). + If not using AVA, you must pass either `true` or an object with a `log` method + which takes a string message as it's only argument. + Additionally, your test running must set `NODE_ENV=test`. 3. `overrideDependencies`: A function with signature `(container, config) => void` which will be called immediately after `registerDependencies`. diff --git a/lib/logger.js b/lib/logger.js index a7b1e17..0124c16 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -16,7 +16,7 @@ export const createLogger = (ctx, t, options) => name: getName(ctx), level, outputMode: isDev ? 'pretty' : 'json', - t, + t: t?.log == null ? { ...t, log: () => {} } : t, ...options, base: { ...createBase(ctx), From b87f9635d437a47db264ae828cf01f279058c532 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Wed, 16 Mar 2022 11:57:21 -0700 Subject: [PATCH 4/7] Add init support --- README.md | 13 ++++++++---- handlers/blue.js | 16 ++++++++++++--- lib/container.js | 22 +++++++++++++++++++-- lib/handlers/factory.js | 23 +++++++++++----------- test/handlers/snapshots/blue.spec.js.md | 1 + test/handlers/snapshots/blue.spec.js.snap | Bin 205 -> 218 bytes 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 336b7b9..330bda0 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,10 @@ export const handler = await createHandler(parameters) This function is registered with the [Awilix] container as a factory function, thus it can access all dependencies registered using `registerDependencies`. +- Register a dependency named `init` as an async function which will be called + once when the handler is created. + This allows the function to perform one-time expensive setup on cold starts + or when provisioned concurrency is used. ### Handler Factories @@ -118,10 +122,11 @@ matching the signature expected by AWS Lambda. All handlers execute these steps in order: 1. Load the config defined by the parameters. 2. Create a new [Awilix] container and register the default dependencies: - `log`, `reqId`, and `processor`. - 3. Parse the event with the parser. - 4. Execute the processor on the event using the configured strategy and wrapper. - 5. Serialize and return the result. + `log`, `reqId`, `init`, and `processor`. + 3. Await the `init` function. + 4. Parse the event with the parser. + 6. Execute the processor on the event using the configured strategy and wrapper. + 7. Serialize and return the result. [AWS Config Executor]: https://github.com/pureskillgg/ace [Awilix]: https://github.com/jeffijoe/awilix diff --git a/handlers/blue.js b/handlers/blue.js index 834c7cb..3dedeb2 100644 --- a/handlers/blue.js +++ b/handlers/blue.js @@ -1,13 +1,23 @@ import Sentry from '@sentry/serverless' -import { asValue } from 'awilix' +import { asFunction, asValue } from 'awilix' import { envString } from '@pureskillgg/ace' import { invokeHandler } from '../index.js' Sentry.AWSLambda.init() +const createInit = + ({ cache }) => + async () => { + cache.isInit = true + } + const registerDependencies = (container, config) => { container.register({ rank: asValue(config.rank) }) + container.register({ + cache: asValue({}), + init: asFunction(createInit).singleton() + }) } const parameters = { @@ -15,9 +25,9 @@ const parameters = { } const createProcessor = - ({ rank }) => + ({ rank, cache }) => async (event, ctx) => { - return { ...event, rank } + return { ...event, rank, isInit: cache.isInit } } export const createHandler = invokeHandler({ diff --git a/lib/container.js b/lib/container.js index d84e9d4..4150318 100644 --- a/lib/container.js +++ b/lib/container.js @@ -1,6 +1,24 @@ -import { asFunction, asValue } from 'awilix' +import { asFunction, asValue, createContainer } from 'awilix' -export { createContainer } from 'awilix' +import { getRequestId } from './request-id.js' +import { createGlobalCtx } from './ctx.js' +import { createLogger } from './logger.js' + +export const createDependencies = (env, t) => { + const container = createContainer() + const ctx = createGlobalCtx(env) + const log = createLogger(ctx, t) + const reqId = getRequestId() + const init = async () => {} + + container.register({ + init: asValue(init), + reqId: asValue(reqId), + log: asValue(log.child({ reqId, isAppLog: false })) + }) + + return container +} export const createScope = (container, { ctx, log, createProcessor }) => { const scope = container.createScope() diff --git a/lib/handlers/factory.js b/lib/handlers/factory.js index 419d50c..b5723ee 100644 --- a/lib/handlers/factory.js +++ b/lib/handlers/factory.js @@ -3,10 +3,10 @@ import { identityParser } from '../parsers/index.js' import { identitySerializer } from '../serializers/index.js' import { createInvokeWrapper } from '../wrappers/index.js' import { createEventStrategy } from '../strategies/index.js' -import { createContainer, createScope } from '../container.js' +import { createDependencies, createScope } from '../container.js' import { createCache } from '../cache.js' import { getConfig } from '../config.js' -import { createCtx, createGlobalCtx } from '../ctx.js' +import { createCtx } from '../ctx.js' const env = { ...process.env } @@ -21,28 +21,29 @@ export const createHandler = logOptions = {} }) => async (parameters, t, overrideDependencies = registerEmptyDependencies) => { - const cache = createCache() - const container = createContainer() - if (process.env.NODE_ENV === 'test' && !t) return async () => {} + const cache = createCache() + const container = createDependencies(env, t) + const config = await getConfig({ parameters, cache, aliases: t ? undefined : env, - log: createLogger(createGlobalCtx(env), t) + log: container.resolve('log') }) + registerDependencies(container, config) + overrideDependencies(container, config) + + const init = container.resolve('init') + await init() + return async (event, context = {}) => { try { const ctx = createCtx(event, context) const log = createLogger(ctx, t, logOptions) - - registerDependencies(container, config) - overrideDependencies(container, config) - const scope = createScope(container, { ctx, log, createProcessor }) - const strategy = createStrategy(scope) const handle = createWrapper(log, strategy, parser, serializer) return handle(event, ctx) diff --git a/test/handlers/snapshots/blue.spec.js.md b/test/handlers/snapshots/blue.spec.js.md index c62f3bf..35ce0ff 100644 --- a/test/handlers/snapshots/blue.spec.js.md +++ b/test/handlers/snapshots/blue.spec.js.md @@ -10,5 +10,6 @@ Generated by [AVA](https://avajs.dev). { foo: 'bar', + isInit: true, rank: 'mock-rank', } diff --git a/test/handlers/snapshots/blue.spec.js.snap b/test/handlers/snapshots/blue.spec.js.snap index cd4713f4bf790719e0a5bb12f44129e5c513b687..1e20546b6f20e26fd5d209bc0da1d925c81e1567 100644 GIT binary patch delta 177 zcmV;i08anS0onmFK~_N^Q*L2!b7*gLAa*kf0{}5wB|)*oQe?=$)yn(@K!QA({B1^u zqMeF;p!E@1FsP9-GIlYKnSq@F1Q2IaRm?yGqMRXviT=vr6!j!GQybx z0s;(-ybO%Y42=9hHB2HP7ONm5b6S2roSl?dgeJ|FS?rmYSpw!V@uNwy6eZ?m!#JF| fK)36HL{f7SlTvfiGZOPsa#D)`9OhH&)&Kwi7N|!z delta 164 zcmV;V09*gs0nGt2K~_N^Q*L2!b7*gLAa*kf0|0$<(fJ|><*YT5STtBMQX39kNf{}V z9e>eZ0r1hV-4Bs6GHFrE%)rh70*oAt%tk=k0*J$bSeTJbkde(lDJwO(gpm=>6c7+# zVB}?BWMW|C2dZHbVPs}tWEEs&PRq}Svy&2w(4<+467#ZQ9L`*z({w>1sX2*BsX6Hx SiFqkGsYL*1j1xY!0000B>_Te* From 6879dc6d5d1a1b795049646202188190ec07418e Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Thu, 17 Mar 2022 23:42:35 -0700 Subject: [PATCH 5/7] Set safe default for options --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index 0124c16..b34b128 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -11,7 +11,7 @@ const envBase = { version: process.env.LOG_VERSION } -export const createLogger = (ctx, t, options) => +export const createLogger = (ctx, t, options = {}) => createMlabsLogger({ name: getName(ctx), level, From ecbd892c3f51aef195b20559335af71c015fee1b Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Fri, 18 Mar 2022 00:27:58 -0700 Subject: [PATCH 6/7] Add fallback to options.base --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index b34b128..9ec0367 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -20,7 +20,7 @@ export const createLogger = (ctx, t, options = {}) => ...options, base: { ...createBase(ctx), - ...options.base + ...options?.base ?? {} } }) From c688067637e1915d6850d9c5da36d436af559666 Mon Sep 17 00:00:00 2001 From: "PureSkill.gg" Date: Fri, 18 Mar 2022 07:34:26 +0000 Subject: [PATCH 7/7] Run format --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index 9ec0367..8d5a9b2 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -20,7 +20,7 @@ export const createLogger = (ctx, t, options = {}) => ...options, base: { ...createBase(ctx), - ...options?.base ?? {} + ...(options?.base ?? {}) } })