Skip to content

Commit

Permalink
update log configs
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Feb 22, 2024
1 parent 27a9882 commit 68bfe4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/logger/cloudwatch.logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AWS from "aws-sdk"
import Bluebird from "bluebird"
import winston from "winston"
import WinstonCloudwatch from "winston-cloudwatch"
import WinstonCloudwatch, { LogObject } from "winston-cloudwatch"

import { config } from "@config/config"

Expand All @@ -10,6 +10,13 @@ import { LogMethod, Loggable } from "./logger.types"

const { combine, timestamp, json, errors } = winston.format

interface MessageFormatterParams {
level: string
message: string
timestamp: string
// Include any other properties you expect to use
}

const withConsoleError = (logFn: LogMethod) => (message: Loggable): void => {
try {
logFn(message)
Expand Down Expand Up @@ -69,8 +76,18 @@ export default class CloudWatchLogger {
logStreamName,
awsRegion,
stderrLevels: ["error"],
format: winston.format.simple(),
format: winston.format.combine(
winston.format.timestamp({
format: "YYYY-MM-DD HH:mm:ss",
}),
winston.format.json()
),
handleExceptions: true,
messageFormatter: (logObject: LogObject) => {
// Extract or default the timestamp
const timestamp = logObject.timestamp || new Date().toISOString()
return `[${timestamp}] ${logObject.level}: ${logObject.message}`
},
}

this._logger.add(new WinstonCloudwatch(cloudwatchConfig))
Expand Down
1 change: 1 addition & 0 deletions src/utils/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tracer from "dd-trace"

tracer.init({
sampleRate: 1,
logInjection: true,
})

export default tracer

0 comments on commit 68bfe4d

Please sign in to comment.