change existing logs format
This commit is contained in:
parent
91a48b2d7d
commit
b5e6191688
@ -2,7 +2,7 @@ import { logger } from "@/src/utils/logger";
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
const rerollRandomModController: RequestHandler = (_req, res) => {
|
const rerollRandomModController: RequestHandler = (_req, res) => {
|
||||||
logger.debug("RerollRandomMod Request", _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 "));
|
logger.debug("RerollRandomMod Request", { info: _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 ") });
|
||||||
res.json({});
|
res.json({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ const options = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// const server = http.createServer(app).listen(80);
|
// const server = http.createServer(app).listen(80);
|
||||||
http.createServer(app).listen(80, () => logger.info("server started on port 80"));
|
http.createServer(app).listen(80, () => logger.info("cache server started on port 80"));
|
||||||
const server = https.createServer(options, app).listen(443, () => logger.info("server started on port 443"));
|
const server = https.createServer(options, app).listen(443, () => logger.info("game server started on port 443"));
|
||||||
|
|
||||||
// server.keepAliveTimeout = 60 * 1000 + 1000;
|
// server.keepAliveTimeout = 60 * 1000 + 1000;
|
||||||
// server.headersTimeout = 60 * 1000 + 2000;
|
// server.headersTimeout = 60 * 1000 + 2000;
|
||||||
|
@ -49,7 +49,7 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
|||||||
if (typeof sessionIdOrRequest === "string") {
|
if (typeof sessionIdOrRequest === "string") {
|
||||||
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
||||||
if (session) {
|
if (session) {
|
||||||
logger.debug("Found Sessions:", session);
|
logger.debug("Found Sessions:", { session });
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
createdBy: session.creatorId,
|
createdBy: session.creatorId,
|
||||||
@ -67,7 +67,7 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("Found Matching Sessions:", matchingSessions);
|
logger.debug("Found Matching Sessions:", { matchingSessions });
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return matchingSessions.map(session => ({
|
return matchingSessions.map(session => ({
|
||||||
|
@ -2,5 +2,5 @@ import morgan from "morgan";
|
|||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
|
|
||||||
export const requestLogger = morgan("dev", {
|
export const requestLogger = morgan("dev", {
|
||||||
stream: { write: message => logger.http(message.trim()) }
|
stream: { write: message => logger.http(message) }
|
||||||
});
|
});
|
||||||
|
@ -108,7 +108,7 @@ export const updateCurrency = async (price: number, usePremium: boolean, account
|
|||||||
currencyChanges[path as currencyKeys] = -price;
|
currencyChanges[path as currencyKeys] = -price;
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug(`currency changes ${JSON.stringify(currencyChanges)}`);
|
logger.debug(`currency changes `, { currencyChanges });
|
||||||
|
|
||||||
//let changes = {} as keyof currencyKeys;
|
//let changes = {} as keyof currencyKeys;
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ const _missionRewardsCheckAllNamings = () => {
|
|||||||
.filter(reward => !blueprintNames[reward.name])
|
.filter(reward => !blueprintNames[reward.name])
|
||||||
.filter(reward => !reward.name.includes(" Endo"))
|
.filter(reward => !reward.name.includes(" Endo"))
|
||||||
.filter(reward => !reward.name.includes(" Credits Cache") && !reward.name.includes("Return: "));
|
.filter(reward => !reward.name.includes(" Credits Cache") && !reward.name.includes("Return: "));
|
||||||
logger.debug(tempRewards);
|
logger.debug(`temp rewards`, { tempRewards });
|
||||||
};
|
};
|
||||||
// _missionRewardsCheckAllNamings();
|
// _missionRewardsCheckAllNamings();
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ if (url === undefined) {
|
|||||||
|
|
||||||
const connectDatabase = async () => {
|
const connectDatabase = async () => {
|
||||||
try {
|
try {
|
||||||
await mongoose.connect(url);
|
await mongoose.connect(`${url}`);
|
||||||
logger.info("connected to MongoDB");
|
logger.info("connected to MongoDB");
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
logger.error("error connecting to MongoDB", error.message);
|
logger.error(`error connecting to MongoDB ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,7 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
|
|||||||
logger.debug("purchase request", purchaseRequest);
|
logger.debug("purchase request", purchaseRequest);
|
||||||
const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem);
|
const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem);
|
||||||
const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", "");
|
const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", "");
|
||||||
logger.debug("Store category", storeCategory);
|
logger.debug(`store category ${storeCategory}`);
|
||||||
|
|
||||||
let inventoryChanges;
|
let inventoryChanges;
|
||||||
switch (storeCategory) {
|
switch (storeCategory) {
|
||||||
@ -88,32 +88,26 @@ export const slotPurchaseNameToSlotName: SlotPurchase = {
|
|||||||
// // new frame = slots -1
|
// // new frame = slots -1
|
||||||
// // number of frames = extra - slots + 2
|
// // number of frames = extra - slots + 2
|
||||||
const handleSlotPurchase = async (slotPurchaseNameFull: string, accountId: string) => {
|
const handleSlotPurchase = async (slotPurchaseNameFull: string, accountId: string) => {
|
||||||
logger.debug("slot name", slotPurchaseNameFull);
|
logger.debug(`slot name ${slotPurchaseNameFull}`);
|
||||||
const slotPurchaseName = parseSlotPurchaseName(
|
const slotPurchaseName = parseSlotPurchaseName(
|
||||||
slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1)
|
slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1)
|
||||||
);
|
);
|
||||||
logger.debug(slotPurchaseName, "slot purchase name");
|
logger.debug(`slot purchase name ${slotPurchaseName}`);
|
||||||
|
|
||||||
await updateSlots(
|
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
|
||||||
accountId,
|
const slotsPerPurchase = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase;
|
||||||
slotPurchaseNameToSlotName[slotPurchaseName].name,
|
|
||||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
|
||||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase
|
|
||||||
);
|
|
||||||
|
|
||||||
logger.debug(
|
await updateSlots(accountId, slotName, slotsPerPurchase, slotsPerPurchase);
|
||||||
slotPurchaseNameToSlotName[slotPurchaseName].name,
|
|
||||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
logger.debug(`added ${slotsPerPurchase} slot ${slotName}`);
|
||||||
"slots added"
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
[slotPurchaseNameToSlotName[slotPurchaseName].name]: {
|
[slotName]: {
|
||||||
count: 0,
|
count: 0,
|
||||||
platinum: 1,
|
platinum: 1,
|
||||||
Slots: slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
Slots: slotsPerPurchase,
|
||||||
Extra: slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase
|
Extra: slotsPerPurchase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -170,7 +164,7 @@ const handlePowersuitPurchase = async (powersuitName: string, accountId: string)
|
|||||||
//TODO: change to getInventory, apply changes then save at the end
|
//TODO: change to getInventory, apply changes then save at the end
|
||||||
const handleTypesPurchase = async (typesName: string, accountId: string) => {
|
const handleTypesPurchase = async (typesName: string, accountId: string) => {
|
||||||
const typeCategory = getStoreItemTypesCategory(typesName);
|
const typeCategory = getStoreItemTypesCategory(typesName);
|
||||||
logger.debug("type category", typeCategory);
|
logger.debug(`type category ${typeCategory}`);
|
||||||
switch (typeCategory) {
|
switch (typeCategory) {
|
||||||
case "SuitCustomizations":
|
case "SuitCustomizations":
|
||||||
return await handleSuitCustomizationsPurchase(typesName, accountId);
|
return await handleSuitCustomizationsPurchase(typesName, accountId);
|
||||||
|
@ -39,10 +39,10 @@ export const handleInventoryItemConfigChange = async (
|
|||||||
case "AdultOperatorLoadOuts": {
|
case "AdultOperatorLoadOuts": {
|
||||||
const operatorConfig = equipment as IOperatorConfigEntry;
|
const operatorConfig = equipment as IOperatorConfigEntry;
|
||||||
const operatorLoadout = inventory[equipmentName];
|
const operatorLoadout = inventory[equipmentName];
|
||||||
logger.debug("operator loadout received", equipmentName, operatorConfig);
|
logger.debug(`operator loadout received ${equipmentName} `, operatorConfig);
|
||||||
// all non-empty entries are one loadout slot
|
// all non-empty entries are one loadout slot
|
||||||
for (const [loadoutId, loadoutConfig] of Object.entries(operatorConfig)) {
|
for (const [loadoutId, loadoutConfig] of Object.entries(operatorConfig)) {
|
||||||
// logger.debug("loadoutId", loadoutId, "loadoutconfig", loadoutConfig);
|
logger.debug(`loadoutId ${loadoutId} loadoutConfig`, { config: loadoutConfig });
|
||||||
const loadout = operatorLoadout.find(loadout => loadout._id?.toString() === loadoutId);
|
const loadout = operatorLoadout.find(loadout => loadout._id?.toString() === loadoutId);
|
||||||
|
|
||||||
// if no config with this id exists, create a new one
|
// if no config with this id exists, create a new one
|
||||||
@ -127,7 +127,7 @@ export const handleInventoryItemConfigChange = async (
|
|||||||
case "DrifterMelee":
|
case "DrifterMelee":
|
||||||
case "Sentinels":
|
case "Sentinels":
|
||||||
case "Horses": {
|
case "Horses": {
|
||||||
logger.debug("general Item config saved", equipmentName, equipment);
|
logger.debug(`general Item config saved of type ${equipmentName}`, { config: equipment });
|
||||||
|
|
||||||
const itemEntries = equipment as IItemEntry;
|
const itemEntries = equipment as IItemEntry;
|
||||||
for (const [itemId, itemConfigEntries] of Object.entries(itemEntries)) {
|
for (const [itemId, itemConfigEntries] of Object.entries(itemEntries)) {
|
||||||
@ -154,7 +154,7 @@ export const handleInventoryItemConfigChange = async (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
logger.error("category not implemented", equipmentName, equipment);
|
logger.error(`category not implemented: ${equipmentName}`, { config: equipment });
|
||||||
}
|
}
|
||||||
//case "OperatorAmps":
|
//case "OperatorAmps":
|
||||||
// case "SentinelWeapons":
|
// case "SentinelWeapons":
|
||||||
|
@ -1,24 +1,51 @@
|
|||||||
import { createLogger, format, transports, Logger, LeveledLogMethod, addColors } from "winston";
|
import { createLogger, format, transports, Logger, LeveledLogMethod, addColors } from "winston";
|
||||||
import "winston-daily-rotate-file";
|
import "winston-daily-rotate-file";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
import { inspect } from "util";
|
import * as util from "util";
|
||||||
import { isEmptyObject } from "@/src/helpers/general";
|
import { isEmptyObject } from "@/src/helpers/general";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
//TODO: in production utils.inspect might be slowing down requests
|
// const combineMessageAndSplat = () => {
|
||||||
|
// return {
|
||||||
|
// transform: (info: any, _opts: any) => {
|
||||||
|
// //combine message and args if any
|
||||||
|
// info.message = util.format(info.message, ...(info[Symbol.for("splat")] || []));
|
||||||
|
// return info;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const alwaysAddMetadata = () => {
|
||||||
|
// return {
|
||||||
|
// transform(info: any) {
|
||||||
|
// if (info[Symbol.for("splat")] === undefined) return info;
|
||||||
|
// info.meta = info[Symbol.for("splat")]; //[0].meta;
|
||||||
|
// return info;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
//TODO: in production utils.inspect might be slowing down requests see utils.inspect
|
||||||
const consolelogFormat = format.printf(info => {
|
const consolelogFormat = format.printf(info => {
|
||||||
if (!isEmptyObject(info.metadata)) {
|
if (!isEmptyObject(info.metadata)) {
|
||||||
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message} ${inspect(info.metadata, {
|
const metadataString = util.inspect(info.metadata, {
|
||||||
showHidden: false,
|
showHidden: false,
|
||||||
depth: null,
|
depth: null,
|
||||||
colors: true
|
colors: true
|
||||||
})}`;
|
});
|
||||||
|
|
||||||
|
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message} ${metadataString}`;
|
||||||
}
|
}
|
||||||
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message}`;
|
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const fileFormat = format.combine(format.uncolorize(), format.timestamp(), format.json());
|
const fileFormat = format.combine(
|
||||||
|
format.uncolorize(),
|
||||||
|
//combineMessageAndSplat(),
|
||||||
|
format.timestamp(),
|
||||||
|
format.json()
|
||||||
|
);
|
||||||
|
|
||||||
const errorLog = new transports.DailyRotateFile({
|
const errorLog = new transports.DailyRotateFile({
|
||||||
filename: "logs/error.log",
|
filename: "logs/error.log",
|
||||||
@ -36,6 +63,8 @@ const consoleLog = new transports.Console({
|
|||||||
format: format.combine(
|
format: format.combine(
|
||||||
format.colorize(),
|
format.colorize(),
|
||||||
format.timestamp({ format: "YYYY-MM-DDTHH:mm:ss:SSS" }), // uses local timezone
|
format.timestamp({ format: "YYYY-MM-DDTHH:mm:ss:SSS" }), // uses local timezone
|
||||||
|
//combineMessageAndSplat(),
|
||||||
|
//alwaysAddMetadata(),
|
||||||
format.errors({ stack: true }),
|
format.errors({ stack: true }),
|
||||||
format.align(),
|
format.align(),
|
||||||
format.metadata({ fillExcept: ["message", "level", "timestamp", "version"] }),
|
format.metadata({ fillExcept: ["message", "level", "timestamp", "version"] }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user