Skip to main content

Logger

The Logger module lets you write game messages to the console, choose which levels are shown, and observe accepted log calls.

Setup​

Initialize the SDK and use its logger component:

import * as ArkadiumSdk from '@arkadiuminc/sdk';

const sdk = await ArkadiumSdk.getInstance();

sdk.logger.warn('A game resource is unavailable');

Log levels​

readonly Level: typeof LogLevel exposes the LogLevel enum as sdk.logger.Level. Its values are DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, and NONE = 4.

setLogLevel(level: LogLevel): void selects the minimum level to show. A call is logged when its numeric level is greater than or equal to the selected level. For example, WARN allows warnings and errors but filters out debug and info messages. NONE suppresses every log call.

sdk.logger.setLogLevel(sdk.logger.Level.INFO);
sdk.logger.info('Game started');

const currentLevel = sdk.logger.getLogLevel();

getLogLevel(): LogLevel returns the current level. The initial level is WARN, or DEBUG if SDK debug mode was already enabled when the Logger was constructed. Calling setLogLevel explicitly sets the level; changing debug mode later does not automatically update an existing Logger's level.

Prefix​

setLogPrefix(prefix: string): void changes the text placed before the timestamp and level in console output. The SDK sets the initial prefix to [ArkadiumGameSDK].

sdk.logger.setLogPrefix('[MyGame]');
sdk.logger.warn('Using a cached level');

Log methods​

Each method accepts any number of arguments and returns void. Accepted calls use the matching console method, with the prefix, timestamp, and level before the arguments.

Logger methodConsole method
debug(...args: any[]): voidconsole.debug
info(...args: any[]): voidconsole.info
warn(...args: any[]): voidconsole.warn
error(...args: any[]): voidconsole.error
sdk.logger.debug('Loaded configuration', { difficulty: 'normal' });
sdk.logger.info('Game started');
sdk.logger.warn('Using a cached level');
sdk.logger.error('Could not save progress', { level: 3 });

Calls below the selected level do not reach the console.

Log events​

onLogEvent(observer: ObserverFn<{ level: LogLevel; args: any[] }>): void registers a callback. The callback receives the numeric level and original args for each accepted call. The Logger notifies observers before writing to the console; filtered calls produce no event. The public interface does not provide an unsubscribe method.

const logEvents: Array<{ level: number; args: any[] }> = [];

sdk.logger.onLogEvent((event) => {
logEvents.push(event);
});