release/2024-11-01 - Misc fixes

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-10-29 08:19:58 -07:00
parent fc3ea2bdf8
commit 23f8f69bbe
2 changed files with 16 additions and 9 deletions

View File

@@ -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);

View File

@@ -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(),