feature/IO-2998-enhanced-api-logging - Finish
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -24,17 +24,18 @@ const createLogger = () => {
|
||||
|
||||
if (isLocal) {
|
||||
winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
console.log(`Winston Transports set to LocalStack end point: ${winstonCloudwatchTransportDefaults.endpoint}`);
|
||||
console.log(
|
||||
`Winston Transports set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}`
|
||||
);
|
||||
}
|
||||
|
||||
const developmentTransports = [
|
||||
const getDevelopmentTransports = () => [
|
||||
new winston.transports.Console({
|
||||
level: "silly",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(), // Colorize the output
|
||||
winston.format.timestamp(), // Add timestamps
|
||||
winston.format.colorize(),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(({ level, message, timestamp, user, record, object }) => {
|
||||
// Format the log message for pretty printing
|
||||
return `${timestamp} [${level}]: ${message} ${
|
||||
user ? `| user: ${JSON.stringify(user)}` : ""
|
||||
} ${record ? `| record: ${JSON.stringify(record)}` : ""} ${
|
||||
@@ -44,7 +45,8 @@ const createLogger = () => {
|
||||
)
|
||||
})
|
||||
];
|
||||
const productionTransports = [
|
||||
|
||||
const getProductionTransports = () => [
|
||||
new WinstonCloudWatch({
|
||||
level: "error",
|
||||
logStreamName: "errors",
|
||||
@@ -65,9 +67,9 @@ const createLogger = () => {
|
||||
const winstonLogger = winston.createLogger({
|
||||
format: winston.format.json(),
|
||||
transports:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? productionTransports
|
||||
: [...developmentTransports, ...productionTransports]
|
||||
process.env.NODE_ENV === "production"
|
||||
? getProductionTransports()
|
||||
: [...getDevelopmentTransports(), ...getProductionTransports()]
|
||||
});
|
||||
|
||||
return (message, type, user, record, object) => {
|
||||
@@ -80,7 +82,8 @@ const createLogger = () => {
|
||||
});
|
||||
};
|
||||
} catch (e) {
|
||||
return console.log;
|
||||
console.error("Logger setup failed", e);
|
||||
return () => {}; // Return a no-op function in case of failure
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user