Add verbL and verbH levels to Logger

This commit is contained in:
memetrollsXD 2022-08-03 01:04:34 +02:00
parent 639ae9b186
commit be8200ebf3
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
3 changed files with 20 additions and 4 deletions

View File

@ -58,7 +58,8 @@ export default class Session {
public async handlePacket(packet: Packet) { public async handlePacket(packet: Packet) {
if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName) if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName)
this.c.debug(packet.body); this.c.verbL(packet.body);
this.c.verbH(packet.rawData);
import(`../packets/${packet.protoName}`).then(mod => { import(`../packets/${packet.protoName}`).then(mod => {
mod.default(this, packet); mod.default(this, packet);
@ -83,9 +84,10 @@ export default class Session {
} }
public send(name: PacketName, body: {}) { public send(name: PacketName, body: {}) {
this.c.debug(body); this.c.verbL(body);
const packet = Packet.encode(name, body); const packet = Packet.encode(name, body);
if (!packet) return; if (!packet) return;
this.c.verbH(packet.rawData);
if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName); if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName);
this.kcpobj.send(packet.rawData); this.kcpobj.send(packet.rawData);
} }

View File

@ -5,6 +5,8 @@ export enum VerboseLevel {
NONE = 0, // No logging except for errors NONE = 0, // No logging except for errors
WARNS = 1, // Log warns WARNS = 1, // Log warns
ALL = 2, // Warns and (useless) debug ALL = 2, // Warns and (useless) debug
VERBL = 3, // Warns, debug and verbose
VERBH = 4, // Warns, debug, verbose and very verbose (thanks copilot this is so funny)
} }
type Color = 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | 'black' | 'italic' | 'bold' | 'underline' | 'strikethrough' | 'inverse' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgBlack' | 'bgGray' | 'bgItalic'; type Color = 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | 'black' | 'italic' | 'bold' | 'underline' | 'strikethrough' | 'inverse' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgBlack' | 'bgGray' | 'bgItalic';
@ -50,4 +52,16 @@ export default class Logger {
console.log(`[${this.getDate().white.bold}] ${`DEBUG<${this.name}>`.bgBlue.bold}`, ...args); console.log(`[${this.getDate().white.bold}] ${`DEBUG<${this.name}>`.bgBlue.bold}`, ...args);
this.trail(new Error().stack!.split('\n').slice(2).join('\n')); this.trail(new Error().stack!.split('\n').slice(2).join('\n'));
} }
public verbL(...args: any) {
if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBL) return;
console.log(`[${this.getDate().white.bold}] ${`VERBL<${this.name}>`.bgCyan.bold}`, ...args);
this.trail(new Error().stack!.split('\n').slice(2).join('\n'));
}
public verbH(...args: any) {
if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBH) return;
console.log(`[${this.getDate().white.bold}] ${`VERBH<${this.name}>`.bgCyan.bold}`, ...args);
this.trail(new Error().stack!.split('\n').slice(2).join('\n'));
}
} }

View File

@ -2,7 +2,7 @@
import * as types from "../data/proto/StarRail"; import * as types from "../data/proto/StarRail";
import protobufjs from "protobufjs"; import protobufjs from "protobufjs";
import { CmdID, PacketName } from "../server/kcp/Packet" import { CmdID, PacketName } from "../server/kcp/Packet"
import Logger from "./Logger"; import Logger, { VerboseLevel } from "./Logger";
const c = new Logger("ProtoFactory"); const c = new Logger("ProtoFactory");
class MessageType<T> { class MessageType<T> {
@ -56,7 +56,7 @@ export default class ProtoFactory {
} }
} }
c.debug(`Initialized with ${messageTypeMap.size} types`); if (Logger.VERBOSE_LEVEL > VerboseLevel.ALL) c.log(`Initialized with ${messageTypeMap.size} types`);
//c.log(this.getName(types.PlayerLoginScRsp)) //c.log(this.getName(types.PlayerLoginScRsp))
return; return;