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";
|
||||
|
||||
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({});
|
||||
};
|
||||
|
||||
|
@ -13,8 +13,8 @@ const options = {
|
||||
};
|
||||
|
||||
// const server = http.createServer(app).listen(80);
|
||||
http.createServer(app).listen(80, () => logger.info("server started on port 80"));
|
||||
const server = https.createServer(options, app).listen(443, () => logger.info("server started on port 443"));
|
||||
http.createServer(app).listen(80, () => logger.info("cache server started on port 80"));
|
||||
const server = https.createServer(options, app).listen(443, () => logger.info("game server started on port 443"));
|
||||
|
||||
// server.keepAliveTimeout = 60 * 1000 + 1000;
|
||||
// server.headersTimeout = 60 * 1000 + 2000;
|
||||
|
@ -49,7 +49,7 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
||||
if (typeof sessionIdOrRequest === "string") {
|
||||
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
||||
if (session) {
|
||||
logger.debug("Found Sessions:", session);
|
||||
logger.debug("Found Sessions:", { session });
|
||||
return [
|
||||
{
|
||||
createdBy: session.creatorId,
|
||||
@ -67,7 +67,7 @@ function getSession(sessionIdOrRequest: string | IFindSessionRequest): any[] {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
logger.debug("Found Matching Sessions:", matchingSessions);
|
||||
logger.debug("Found Matching Sessions:", { matchingSessions });
|
||||
return true;
|
||||
});
|
||||
return matchingSessions.map(session => ({
|
||||
|
@ -2,5 +2,5 @@ import morgan from "morgan";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
logger.debug(`currency changes ${JSON.stringify(currencyChanges)}`);
|
||||
logger.debug(`currency changes `, { currencyChanges });
|
||||
|
||||
//let changes = {} as keyof currencyKeys;
|
||||
|
||||
|
@ -239,7 +239,7 @@ const _missionRewardsCheckAllNamings = () => {
|
||||
.filter(reward => !blueprintNames[reward.name])
|
||||
.filter(reward => !reward.name.includes(" Endo"))
|
||||
.filter(reward => !reward.name.includes(" Credits Cache") && !reward.name.includes("Return: "));
|
||||
logger.debug(tempRewards);
|
||||
logger.debug(`temp rewards`, { tempRewards });
|
||||
};
|
||||
// _missionRewardsCheckAllNamings();
|
||||
|
||||
|
@ -12,11 +12,11 @@ if (url === undefined) {
|
||||
|
||||
const connectDatabase = async () => {
|
||||
try {
|
||||
await mongoose.connect(url);
|
||||
await mongoose.connect(`${url}`);
|
||||
logger.info("connected to MongoDB");
|
||||
} catch (error: unknown) {
|
||||
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);
|
||||
const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem);
|
||||
const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", "");
|
||||
logger.debug("Store category", storeCategory);
|
||||
logger.debug(`store category ${storeCategory}`);
|
||||
|
||||
let inventoryChanges;
|
||||
switch (storeCategory) {
|
||||
@ -88,32 +88,26 @@ export const slotPurchaseNameToSlotName: SlotPurchase = {
|
||||
// // new frame = slots -1
|
||||
// // number of frames = extra - slots + 2
|
||||
const handleSlotPurchase = async (slotPurchaseNameFull: string, accountId: string) => {
|
||||
logger.debug("slot name", slotPurchaseNameFull);
|
||||
logger.debug(`slot name ${slotPurchaseNameFull}`);
|
||||
const slotPurchaseName = parseSlotPurchaseName(
|
||||
slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1)
|
||||
);
|
||||
logger.debug(slotPurchaseName, "slot purchase name");
|
||||
logger.debug(`slot purchase name ${slotPurchaseName}`);
|
||||
|
||||
await updateSlots(
|
||||
accountId,
|
||||
slotPurchaseNameToSlotName[slotPurchaseName].name,
|
||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase
|
||||
);
|
||||
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
|
||||
const slotsPerPurchase = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase;
|
||||
|
||||
logger.debug(
|
||||
slotPurchaseNameToSlotName[slotPurchaseName].name,
|
||||
slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
||||
"slots added"
|
||||
);
|
||||
await updateSlots(accountId, slotName, slotsPerPurchase, slotsPerPurchase);
|
||||
|
||||
logger.debug(`added ${slotsPerPurchase} slot ${slotName}`);
|
||||
|
||||
return {
|
||||
InventoryChanges: {
|
||||
[slotPurchaseNameToSlotName[slotPurchaseName].name]: {
|
||||
[slotName]: {
|
||||
count: 0,
|
||||
platinum: 1,
|
||||
Slots: slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase,
|
||||
Extra: slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase
|
||||
Slots: 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
|
||||
const handleTypesPurchase = async (typesName: string, accountId: string) => {
|
||||
const typeCategory = getStoreItemTypesCategory(typesName);
|
||||
logger.debug("type category", typeCategory);
|
||||
logger.debug(`type category ${typeCategory}`);
|
||||
switch (typeCategory) {
|
||||
case "SuitCustomizations":
|
||||
return await handleSuitCustomizationsPurchase(typesName, accountId);
|
||||
|
@ -39,10 +39,10 @@ export const handleInventoryItemConfigChange = async (
|
||||
case "AdultOperatorLoadOuts": {
|
||||
const operatorConfig = equipment as IOperatorConfigEntry;
|
||||
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
|
||||
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);
|
||||
|
||||
// if no config with this id exists, create a new one
|
||||
@ -127,7 +127,7 @@ export const handleInventoryItemConfigChange = async (
|
||||
case "DrifterMelee":
|
||||
case "Sentinels":
|
||||
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;
|
||||
for (const [itemId, itemConfigEntries] of Object.entries(itemEntries)) {
|
||||
@ -154,7 +154,7 @@ export const handleInventoryItemConfigChange = async (
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
logger.error("category not implemented", equipmentName, equipment);
|
||||
logger.error(`category not implemented: ${equipmentName}`, { config: equipment });
|
||||
}
|
||||
//case "OperatorAmps":
|
||||
// case "SentinelWeapons":
|
||||
|
@ -1,24 +1,51 @@
|
||||
import { createLogger, format, transports, Logger, LeveledLogMethod, addColors } from "winston";
|
||||
import "winston-daily-rotate-file";
|
||||
import * as dotenv from "dotenv";
|
||||
import { inspect } from "util";
|
||||
import * as util from "util";
|
||||
import { isEmptyObject } from "@/src/helpers/general";
|
||||
|
||||
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 => {
|
||||
if (!isEmptyObject(info.metadata)) {
|
||||
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message} ${inspect(info.metadata, {
|
||||
const metadataString = util.inspect(info.metadata, {
|
||||
showHidden: false,
|
||||
depth: null,
|
||||
colors: true
|
||||
})}`;
|
||||
});
|
||||
|
||||
return `${info.timestamp} [${info.version}] ${info.level}: ${info.message} ${metadataString}`;
|
||||
}
|
||||
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({
|
||||
filename: "logs/error.log",
|
||||
@ -36,6 +63,8 @@ const consoleLog = new transports.Console({
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.timestamp({ format: "YYYY-MM-DDTHH:mm:ss:SSS" }), // uses local timezone
|
||||
//combineMessageAndSplat(),
|
||||
//alwaysAddMetadata(),
|
||||
format.errors({ stack: true }),
|
||||
format.align(),
|
||||
format.metadata({ fillExcept: ["message", "level", "timestamp", "version"] }),
|
||||
|
Loading…
x
Reference in New Issue
Block a user