74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
const InstanceManager = require("../utils/instanceMgr").default;
|
|
const winston = require("winston");
|
|
const WinstonCloudWatch = require("winston-cloudwatch");
|
|
|
|
const region = InstanceManager({
|
|
imex: "ca-central-1",
|
|
rome: "us-east-2"
|
|
});
|
|
|
|
const logGroupName = process.env.CLOUDWATCH_LOG_GROUP;
|
|
|
|
const winstonLogger = winston.createLogger({
|
|
//level: "debug",
|
|
format: winston.format.json(),
|
|
transports: [
|
|
...(process.env.NODE_ENV !== "production"
|
|
? [
|
|
new winston.transports.Console({
|
|
level: "silly",
|
|
format: winston.format.combine(
|
|
winston.format.colorize(), // Colorize the output
|
|
winston.format.timestamp(), // Add timestamps
|
|
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)}` : ""} ${
|
|
object ? `| object: ${JSON.stringify(object, null, 2)}` : ""
|
|
}`;
|
|
})
|
|
)
|
|
})
|
|
]
|
|
: [
|
|
new WinstonCloudWatch({
|
|
level: "error",
|
|
logGroupName: logGroupName,
|
|
logStreamName: "errors",
|
|
awsRegion: region,
|
|
jsonMessage: true
|
|
}),
|
|
new WinstonCloudWatch({
|
|
level: "warn",
|
|
logGroupName: logGroupName,
|
|
logStreamName: "warn",
|
|
awsRegion: region,
|
|
jsonMessage: true
|
|
}),
|
|
new WinstonCloudWatch({
|
|
level: "debug",
|
|
logGroupName: logGroupName,
|
|
logStreamName: "debug",
|
|
awsRegion: region,
|
|
jsonMessage: true
|
|
})
|
|
])
|
|
]
|
|
});
|
|
|
|
function log(message, type, user, record, object) {
|
|
// winstonLogger.debug(message, user, record, object);
|
|
|
|
winstonLogger.log({
|
|
level: type.toLowerCase(),
|
|
message: message,
|
|
user: user,
|
|
record: record,
|
|
meta: object
|
|
});
|
|
|
|
}
|
|
|
|
module.exports = { log };
|