-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1185 from akhilmhdh/feat/pino-cloudwatch
feat(aws-cloudwatch): added support for aws cloudwatch transport in pino
- Loading branch information
Showing
6 changed files
with
14,534 additions
and
12,069 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { logger } from "./logger"; | ||
export { logger, initLogger } from "./logger"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,56 @@ | ||
import pino from "pino"; | ||
|
||
export const logger = pino({ | ||
level: process.env.PINO_LOG_LEVEL || "trace", | ||
timestamp: pino.stdTimeFunctions.isoTime, | ||
formatters: { | ||
bindings: (bindings) => { | ||
return { | ||
import pino, { Logger } from "pino"; | ||
import { getAwsCloudWatchLog, getNodeEnv } from "../../config"; | ||
|
||
export let logger: Logger; | ||
|
||
export const initLogger = async () => { | ||
const awsCloudWatchLogCfg = await getAwsCloudWatchLog(); | ||
const nodeEnv = await getNodeEnv(); | ||
const isProduction = nodeEnv === "production"; | ||
const targets: pino.TransportMultiOptions["targets"][number][] = [ | ||
isProduction | ||
? { level: "trace", target: "pino/file", options: {} } | ||
: { | ||
level: "info", | ||
target: "pino-pretty", // must be installed separately | ||
options: { | ||
colorize: true | ||
} | ||
} | ||
]; | ||
|
||
if (awsCloudWatchLogCfg) { | ||
targets.push({ | ||
target: "@serdnam/pino-cloudwatch-transport", | ||
level: "info", | ||
options: { | ||
logGroupName: awsCloudWatchLogCfg.logGroupName, | ||
logStreamName: awsCloudWatchLogCfg.logGroupName, | ||
awsRegion: awsCloudWatchLogCfg.region, | ||
awsAccessKeyId: awsCloudWatchLogCfg.accessKeyId, | ||
awsSecretAccessKey: awsCloudWatchLogCfg.accessKeySecret, | ||
interval: awsCloudWatchLogCfg.interval | ||
} | ||
}); | ||
} | ||
|
||
const transport = pino.transport({ | ||
targets | ||
}); | ||
|
||
logger = pino( | ||
{ | ||
level: process.env.PINO_LOG_LEVEL || "trace", | ||
formatters: { | ||
bindings: (bindings) => { | ||
return { | ||
pid: bindings.pid, | ||
hostname: bindings.hostname | ||
// node_version: process.version | ||
}; | ||
}; | ||
} | ||
} | ||
}, | ||
} | ||
}); | ||
transport | ||
); | ||
}; |