-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating separate sentryLogger and cloudwatchLogger, tying them toget…
…her in global.ts
- Loading branch information
Showing
10 changed files
with
6,632 additions
and
4,135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import dotenv from 'dotenv' | ||
import { createLogger, transports, format } from "winston"; | ||
import WinstonCloudWatch from 'winston-cloudwatch'; | ||
|
||
dotenv.config() | ||
|
||
const cloudwatchLogger = createLogger({ | ||
format: format.json(), | ||
transports: [ | ||
new WinstonCloudWatch({ | ||
logGroupName: process.env.LOG_GROUP_NAME, | ||
logStreamName: process.env.LOG_STREAM_NAME, | ||
awsRegion: process.env.AWS_REGION, | ||
createLogGroup: true, | ||
createLogStream: true, | ||
}), | ||
], | ||
}); | ||
|
||
export default cloudwatchLogger |
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,16 +1,57 @@ | ||
import logger from './logger' | ||
import cloudwatchLogger from './cloudwatchLogger'; | ||
import sentryLogger from './sentryLogger'; | ||
|
||
// change global console.log to winston logger type | ||
(function overrideConsoleMethods() { | ||
const statusDict: Array<string> = ["error", "warn", "info", "http", "verbose", "debug"]; | ||
|
||
(() => { | ||
console.log = function (message, status = "info") { | ||
// the available status | ||
const status_dict = ["error", "warn", "info", "http", "verbose", "debug"]; | ||
// if status is not part of the availability, change it to info | ||
if (!status_dict.includes(status)) { | ||
/* We're preserving the original console.log functionality just in case there are log messages that don't fit into | ||
the predefined statuses. This helps in making sure we don't unintentionally suppress important log messages. */ | ||
const originalConsoleLog = console.log; | ||
|
||
console.log = function (message: string, status = "info") { | ||
if (statusDict.indexOf(status) !== -1) { | ||
status = "info"; | ||
} | ||
logger.log(status, message); | ||
|
||
switch (status) { | ||
case "error": | ||
cloudwatchLogger.error(message); | ||
sentryLogger.error(message); | ||
break; | ||
case "warn": | ||
cloudwatchLogger.warn(message); | ||
break; | ||
case "info": | ||
cloudwatchLogger.info(message); | ||
break; | ||
case "http": | ||
cloudwatchLogger.log('http', message); | ||
break; | ||
case "debug": | ||
case "verbose": | ||
cloudwatchLogger.debug(message); | ||
break; | ||
} | ||
}; | ||
|
||
console.info = function (...args) { | ||
const message = args.join(' '); | ||
cloudwatchLogger.info(message); | ||
}; | ||
})(); | ||
|
||
console.warn = function (...args) { | ||
const message = args.join(' '); | ||
cloudwatchLogger.warn(message); | ||
}; | ||
|
||
console.error = function (...args) { | ||
const message = args.join(' '); | ||
cloudwatchLogger.error(message); | ||
sentryLogger.error(message); | ||
}; | ||
|
||
console.debug = function (...args) { | ||
const message = args.join(' '); | ||
cloudwatchLogger.debug(message); | ||
}; | ||
})(); |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import dotenv from 'dotenv'; | ||
import { createLogger, transports, format } from 'winston'; | ||
import WinstonCloudWatch from 'winston-cloudwatch'; | ||
|
||
dotenv.config(); | ||
|
||
// Determine log group and stream based on NODE_ENV | ||
let logGroupName: string; | ||
let logStreamName: string; | ||
|
||
switch (process.env.NODE_ENV) { | ||
case 'production': | ||
logGroupName = process.env.PROD_LOG_GROUP_NAME || ''; | ||
logStreamName = process.env.PROD_LOG_STREAM_NAME || ''; | ||
break; | ||
case 'test': | ||
logGroupName = process.env.TEST_LOG_GROUP_NAME || ''; | ||
logStreamName = process.env.TEST_LOG_STREAM_NAME || ''; | ||
break; | ||
case 'development': | ||
default: | ||
logGroupName = process.env.DEV_LOG_GROUP_NAME || ''; | ||
logStreamName = process.env.DEV_LOG_STREAM_NAME || ''; | ||
break; | ||
} | ||
|
||
const cloudwatchLogger = createLogger({ | ||
format: format.json(), | ||
transports: [ | ||
new WinstonCloudWatch({ | ||
logGroupName: logGroupName, | ||
logStreamName: logStreamName, | ||
awsRegion: process.env.AWS_REGION, | ||
createLogGroup: true, | ||
createLogStream: true, | ||
}), | ||
], | ||
}); | ||
|
||
export default cloudwatchLogger; |
Oops, something went wrong.