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

Add version variable to cdk template logger #1548

Merged
merged 22 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
5 changes: 5 additions & 0 deletions .changeset/slow-seahorses-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

template/lambda-sqs-worker-cdk: Add VERSION variable to `lambda-sqs-worker-cdk` logger
GeordieEK marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion template/lambda-sqs-worker-cdk/infra/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export const configs: Record<Environment, Config> = {
},
};

export const config = configs[environment];
export const config: Config = configs[environment];
1 change: 1 addition & 0 deletions template/lambda-sqs-worker-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@aws-sdk/client-lambda": "^3.363.0",
"@aws-sdk/client-sns": "^3.363.0",
"@seek/logger": "^6.0.0",
"skuba-dive": "^2.0.0",
"zod": "^3.19.1"
},
"devDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions template/lambda-sqs-worker-cdk/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import createLogger from '@seek/logger';
import type { SQSEvent, SQSHandler } from 'aws-lambda';

const logger = createLogger({
name: '<%- serviceName %>',
import { config } from './config';

export const logger = createLogger({
base: {
environment: config.environment,
version: config.version,
},

level: config.logLevel,

name: config.name,

transport:
config.environment === 'local' ? { target: 'pino-pretty' } : undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to declare pino-pretty as a dev dep?

});

/**
Expand Down
51 changes: 51 additions & 0 deletions template/lambda-sqs-worker-cdk/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Env } from 'skuba-dive';

interface Config {
environment: Environment;

logLevel: string;
name: string;
version: string;
}

type Environment = (typeof environments)[number];

const dev = 'dev';
const prod = 'prod';

const environments = ['local', 'test', dev, prod] as const;

const environment = Env.oneOf(environments)('ENVIRONMENT');

/* istanbul ignore next: config verification makes more sense in a smoke test */
const configs: Record<Environment, () => Omit<Config, 'environment'>> = {
local: () => ({
logLevel: 'debug',
name: '<%- serviceName %>',
version: 'local',
}),

test: () => ({
...configs.local(),

logLevel: Env.string('LOG_LEVEL', { default: 'silent' }),
version: 'test',
}),

[dev]: () => ({
...configs[prod](),

logLevel: 'debug',
}),

[prod]: () => ({
logLevel: 'info',
name: Env.string('SERVICE'),
samchungy marked this conversation as resolved.
Show resolved Hide resolved
version: Env.string('VERSION'),
}),
};

export const config: Config = {
...configs[environment](),
environment,
};