diff --git a/server/email/mailer.js b/server/email/mailer.js index 6503e1f8c..654f56cb3 100644 --- a/server/email/mailer.js +++ b/server/email/mailer.js @@ -3,6 +3,7 @@ const { defaultProvider } = require("@aws-sdk/credential-provider-node"); const { default: InstanceManager } = require("../utils/instanceMgr"); const aws = require("@aws-sdk/client-ses"); const nodemailer = require("nodemailer"); +const logger = require("../utils/logger"); const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME); @@ -19,7 +20,7 @@ const sesConfig = { if (isLocal) { sesConfig.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`; - console.log(`SES Mailer set to LocalStack end point: ${sesConfig.endpoint}`); + logger.logger.debug(`SES Mailer set to LocalStack end point: ${sesConfig.endpoint}`); } const ses = new aws.SES(sesConfig); diff --git a/server/utils/logger.js b/server/utils/logger.js index 75d282fa2..b1e96e02d 100644 --- a/server/utils/logger.js +++ b/server/utils/logger.js @@ -8,7 +8,7 @@ const InstanceManager = require("../utils/instanceMgr").default; const winston = require("winston"); const WinstonCloudWatch = require("winston-cloudwatch"); const { isString, isEmpty } = require("lodash"); -const { networkInterfaces } = require("node:os"); +const { networkInterfaces, hostname } = require("node:os"); const createLogger = () => { try { @@ -28,9 +28,6 @@ const createLogger = () => { if (isLocal) { winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`; - console.log( - `Winston Transports set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}` - ); } const levelFilter = (levels) => { @@ -43,19 +40,22 @@ const createLogger = () => { })(); }; - const getPrivateIP = () => { + const getHostNameOrIP = () => { + // Try to get the hostname first + const hostName = hostname(); + if (hostName) return hostName; + const interfaces = networkInterfaces(); for (const name of Object.keys(interfaces)) { for (const iface of interfaces[name]) { - // Find an IPv4 address that's not internal (like localhost) if (iface.family === "IPv4" && !iface.internal) { return iface.address; } } } + return "127.0.0.1"; }; - const createProductionTransport = (level, logStreamName, filters) => { return new WinstonCloudWatch({ level, @@ -65,7 +65,7 @@ const createLogger = () => { }); }; - const hostname = process.env.HOSTNAME || getPrivateIP(); + const hostname = process.env.HOSTNAME || getHostNameOrIP(); const getDevelopmentTransports = () => [ new winston.transports.Console({ @@ -106,6 +106,12 @@ const createLogger = () => { : [...getDevelopmentTransports(), ...getProductionTransports()] }); + if (isLocal) { + winstonLogger.debug( + `CloudWatch set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}` + ); + } + const log = (message, type, user, record, meta) => { winstonLogger.log({ level: type.toLowerCase(),