release/2024-11-01 - Misc fixes
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user