Skip to content

Commit

Permalink
fix: pretty print tables when logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Aug 25, 2024
1 parent 41411af commit 2fa17ad
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 11 deletions.
14 changes: 10 additions & 4 deletions packages/core/src/client/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CommandGroup } from "../shared/core/command";
import { BaseRegistry } from "../shared/core/registry";
import { SyncData } from "../shared/network";
import { ObjectUtil, ReadonlyDeep } from "../shared/util/data";
import { inspect } from "../shared/util/inspect";
import { CenturionLogLevel } from "../shared/util/log";
import { ServerCommand } from "./command";
import { ClientConfig } from "./types";
Expand Down Expand Up @@ -97,10 +98,15 @@ export class ClientRegistry extends BaseRegistry<ReadonlyDeep<ClientConfig>> {
groups.push(group);
}

this.logger.debug(
`Received sync data from server (commands: ${data.commands.size()}, groups: ${groups.size()})`,
data,
);
if (this.logger.level <= CenturionLogLevel.Debug) {
this.logger.debug(
`Received sync data from server (commands: ${data.commands.size()}, groups: ${groups.size()})`,
inspect(data, {
depth: 2,
}),
);
}

this.registerGroup(...groups);
this.registerServerCommands(data.commands);

Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/server/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Players } from "@rbxts/services";
import { CommandOptions, GroupOptions, RegistryPath } from "../shared";
import {
CenturionLogLevel,
CommandOptions,
GroupOptions,
RegistryPath,
} from "../shared";
import {
BaseCommand,
CommandGroup,
Expand All @@ -8,6 +13,7 @@ import {
import { BaseRegistry } from "../shared/core/registry";
import { SyncData } from "../shared/network";
import { ArrayUtil, ReadonlyDeep } from "../shared/util/data";
import { inspect } from "../shared/util/inspect";
import { ServerConfig } from "./types";

export class ServerRegistry extends BaseRegistry<ReadonlyDeep<ServerConfig>> {
Expand Down Expand Up @@ -79,8 +85,15 @@ export class ServerRegistry extends BaseRegistry<ReadonlyDeep<ServerConfig>> {
}
}

this.logger.debug(`Syncing data to ${player.Name}`, data);
this.config.network.syncDispatch.Fire(player, data);
if (this.logger.level <= CenturionLogLevel.Debug) {
this.logger.debug(
`Synced data to ${player.Name}`,
inspect(data, {
depth: 2,
}),
);
}
}

protected addCommand(command: BaseCommand, group?: CommandGroup | undefined) {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/shared/util/inspect.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface InspectOptions {
depth: number;
newline: string;
indent: string;
process: (item: unknown, path: unknown[]) => unknown;
}

export function inspect(
value: unknown,
options?: Partial<InspectOptions>,
): string;
Loading

0 comments on commit 2fa17ad

Please sign in to comment.