Skip to content

Commit

Permalink
tidy up our logging too
Browse files Browse the repository at this point in the history
  • Loading branch information
tmclaugh committed Oct 22, 2024
1 parent e4bd300 commit 997debd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/handlers/CreateEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export async function putEntity(entity: Entity): Promise<PutItemCommandOutput> {
try {
const command = new PutItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('PutItemCommand succeeded', { output })
LOGGER.debug('PutItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('PutItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
LOGGER.error({
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
error: <DynamoDBServiceException>error,
entity
})
throw error
}
Expand All @@ -69,7 +71,7 @@ export async function putEntity(entity: Entity): Promise<PutItemCommandOutput> {


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

const entity: Entity = JSON.parse(event.body || '{}') // Already validated body at Gateway

Expand Down
18 changes: 12 additions & 6 deletions src/handlers/DeleteEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ export async function deleteEntity(
try {
const command = new DeleteItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('DeleteItemCommand succeeded', { output })
LOGGER.debug('DeleteItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('DeleteItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
})
LOGGER.error({
error: <DynamoDBServiceException>error,
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
entity: {
namespace,
kind,
name
}
})
throw error
}

Expand All @@ -52,7 +58,7 @@ export async function deleteEntity(


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

const namespace = event.pathParameters?.namespace as string
const kind = event.pathParameters?.kind as string
Expand Down
18 changes: 12 additions & 6 deletions src/handlers/GetEntity/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ export async function getEntity(
try {
const command = new GetItemCommand(params)
output = await DDB_CLIENT.send(command)
LOGGER.info('GetItemCommand succeeded', { output })
LOGGER.debug('GetItemCommand succeeded', { output })
} catch (error) {
LOGGER.error('GetItemCommand failed', {
error: (<DynamoDBServiceException>error).name,
message: error
})
LOGGER.error({
error: <DynamoDBServiceException>error,
name: (<DynamoDBServiceException>error).name,
message: (<DynamoDBServiceException>error).message,
entity: {
namespace,
kind,
name
}
})
throw error
}

Expand All @@ -64,7 +70,7 @@ export async function getEntity(


export async function handler (event: APIGatewayProxyEvent, _: Context): Promise<APIGatewayProxyResult> {
LOGGER.info('Received event', { event })
LOGGER.debug('Received event', { event })

const namespace = event.pathParameters?.namespace as string
const kind = event.pathParameters?.kind as string
Expand Down

0 comments on commit 997debd

Please sign in to comment.