Updated logging
This commit is contained in:
parent
150200c8cf
commit
ee14b046fa
2 changed files with 17 additions and 4 deletions
|
|
@ -27,6 +27,7 @@ export function log(
|
||||||
|
|
||||||
if (logLevel > currentLogLevel) return;
|
if (logLevel > currentLogLevel) return;
|
||||||
|
|
||||||
|
const resetCode = "\x1b[0m";
|
||||||
const colorCodes: Record<typeof color, string> = {
|
const colorCodes: Record<typeof color, string> = {
|
||||||
red: "\x1b[31m",
|
red: "\x1b[31m",
|
||||||
green: "\x1b[32m",
|
green: "\x1b[32m",
|
||||||
|
|
@ -38,8 +39,20 @@ export function log(
|
||||||
black: "\x1b[30m",
|
black: "\x1b[30m",
|
||||||
gray: "\x1b[90m",
|
gray: "\x1b[90m",
|
||||||
};
|
};
|
||||||
const resetCode = "\x1b[0m";
|
|
||||||
console.log(`${colorCodes[color]}${logger}${resetCode}`, ...args);
|
if (args.length === 1) {
|
||||||
|
console.log(`${colorCodes[color]}${logger}${resetCode} ${args[0]}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.groupCollapsed(`${colorCodes[color]}${logger}${resetCode} ${args[0]}`);
|
||||||
|
try {
|
||||||
|
for (const arg of args.slice(1)) {
|
||||||
|
console.log(arg);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
console.groupEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const size = 20;
|
const size = 20;
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ export function createTransportClient<T extends SchemaMap>(
|
||||||
*/
|
*/
|
||||||
const handleIncomingMessage = (message: TypedMessage) => {
|
const handleIncomingMessage = (message: TypedMessage) => {
|
||||||
if (message.type !== "pong") {
|
if (message.type !== "pong") {
|
||||||
log(2, "ttp", "cyan", "Received:", message.type, message.data, {
|
log(2, "ttp", "cyan", "Received: " + message.type, message.data, {
|
||||||
id: message.id,
|
id: message.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -586,7 +586,7 @@ export function createTransportClient<T extends SchemaMap>(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (type !== "ping") {
|
if (type !== "ping") {
|
||||||
log(2, "ttp", "gray", "Sent:", type, payload, { id: requestId });
|
log(2, "ttp", "gray", "Sent: " + type, payload, { id: requestId });
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageBytes = encodeCommunicationMessage({
|
const messageBytes = encodeCommunicationMessage({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue