Logging
The library logs through the built-in console, prefixed with the module name. TRACE and DEBUG use console.debug, INFO uses console.info, and WARN uses console.warn, so browser DevTools can filter them by level (Chrome hides console.debug unless "Verbose" is enabled). You can set log levels globally or per module (socket, messenger, pubsub) at runtime.
Log levels
LogLevel.TRACE— Very detailed debugging informationLogLevel.DEBUG— Detailed debugging informationLogLevel.INFO— General informational messages (default)LogLevel.WARN— Warning messagesLogLevel.ERROR— Error messages (the library currently logs nothing at this level, so it behaves likeSILENT)LogLevel.FATAL— Fatal error messages (likewise unused)LogLevel.SILENT— Disable all logging
Global log level
import { NetworkTables, LogLevel } from '@ntcore-ts/client';
NetworkTables.setLogLevel(LogLevel.DEBUG);
NetworkTables.setLogLevel(LogLevel.SILENT);Module-specific log levels
import { NetworkTables, LogLevel } from '@ntcore-ts/client';
NetworkTables.setModuleLogLevel('socket', LogLevel.DEBUG);
NetworkTables.setModuleLogLevel('messenger', LogLevel.WARN);
NetworkTables.setModuleLogLevel('pubsub', LogLevel.SILENT);Available modules:
'socket'— WebSocket connection management'messenger'— Message publishing and subscription handling'pubsub'— Topic management and value updates'default'— General library logging
Getting the current log level
import { NetworkTables, LogLevel } from '@ntcore-ts/client';
const currentLevel = NetworkTables.getModuleLogLevel('socket');
console.log(`Socket log level: ${LogLevel[currentLevel]}`);Default behavior
By default, the library logs:
INFO: Connection status, protocol versionWARN: Connection loss, malformed or unhandled messages
DEBUG and TRACE messages (reconnection attempts, topic creation, unknown topics) are hidden unless you lower the log level.
Example output at the default level in the browser:
[SOCKET] Connected on NT 4.1
[SOCKET] Robot Connected!Timestamps
Outside the browser (Node.js, Deno, Bun), each line starts with an ISO timestamp:
2026-11-21T07:54:18.616Z [SOCKET] Connected on NT 4.1In the browser, lines have no timestamp because DevTools can add one ("Show timestamps" in the console settings). Turn timestamps on or off anywhere with setLogTimestamps:
import { setLogTimestamps } from '@ntcore-ts/client';
setLogTimestamps(false);Custom log handler
To send library logs to your own logger, a file, or a remote collector, set a handler. It receives every line that passes the level filter, instead of the console:
import { LogLevel, setLogHandler } from '@ntcore-ts/client';
setLogHandler(({ level, module, message, args, time }) => {
myLogger.log({ level: LogLevel[level], module, message, args, time });
});
// Log to the console again
setLogHandler(null);Direct logger utilities
import { LogLevel, setLogLevel, setModuleLogLevel, LoggerModule } from '@ntcore-ts/client';
setLogLevel(LogLevel.INFO);
setModuleLogLevel('socket' as LoggerModule, LogLevel.DEBUG);