Skip to Content
APIUtilsInterface: ILogger

Interface: ILogger

Logger interface (Port) Defines the contract for logging and analytics in the SDK. Following hexagonal architecture, this is a port that can be implemented by different adapters (Countly, console, custom, etc.)

Example

const logger: ILogger = new CountlyLogger() logger.logEvent("button_click", { buttonId: "submit" }) logger.logError(new Error("Something went wrong"), { userId: "123" })

Methods

logDebug()

logDebug(...args): void;

Logs debug information (only in debug mode)

Parameters

args

unknown[]

Arguments to log

Returns

void


logError()

logError(error, context?): void;

Logs an error to error tracking service

Parameters

error

unknown

The error to log

context?

Record<string, string>

Optional context information

Returns

void


logEvent()

logEvent(eventName, segmentation?): void;

Logs an analytics event

Parameters

eventName

string

Name of the event to log

segmentation?

Record<string, string>

Optional key-value pairs for event context

Returns

void


logWarning()

logWarning(error, context?): void;

Logs a warning (less severe than error)

Parameters

error

unknown

The warning/error to log

context?

Record<string, string>

Optional context information

Returns

void


setDebugMode()?

optional setDebugMode(enabled): void;

Enables or disables debug mode

Parameters

enabled

boolean

Whether debug logging should be enabled

Returns

void


setToken()?

optional setToken(token): void;

Sets the token for segmentation

Parameters

token

string

API token for identifying the SDK instance

Returns

void

Last updated on