The loggerOptions section within the KigoContext allows you to configure logging behavior for your application. This includes setting the log level, providing a custom logger, and utilizing the built-in debug package for managing log output directly in the browser.

Defaults

The code below illustrates setting the KigoContext with the default values for loggerOptions:

const kigoContext = {
  loggerOptions: {
    level: "error",
    customLogger: undefined,
  },
};

Properties

  • level - Defines the level of logging to be used in the application.

    • Default: "error" - The logger will only capture errors by default.
    • Valid values: "debug" | "info" | "warn" | "error"
    • Example:
      loggerOptions: { level: "debug" }
      
  • customLogger - Allows you to specify a custom logger implementation that adheres to the CustomLogger interface.

    • Default: undefined - If set to undefined, the default logging mechanism will be used.
    • Valid values: CustomLogger (an object implementing custom logging methods)
    • Example:
      loggerOptions: { customLogger: new MyCustomLogger() }
      

CustomLogger Interface

If you choose to implement a customLogger, it should adhere to the following interface:

export interface CustomLogger {
  log(level: LogLevel, logEntry: LogEntry): void;
}

export type LogLevel = 'debug' | 'info' | 'warn' | 'error';

export interface LogEntry {
  message: string;
  timestamp: string;
  level: LogLevel;
  namespace: string;
  context?: Record<string, any>;
}

LogEntry Structure

The logEntry object passed to log contains the following properties:

  • message: The log message.
  • timestamp: The timestamp of the log entry.
  • level: The level of the log ("debug", "info", "warn", "error").
  • namespace: The namespace associated with the log (e.g., "kigo-sdk:info").
  • context: (Optional) Additional context or metadata associated with the log entry.

The Debug Package

The logging functionality in the KigoContext uses the debug package under the hood. This package provides a simple way to manage logging output in the browser. You can enable or disable specific logging levels by setting the localStorage.debug property.

Enabling/Disabling Logging in the Browser

To manage logging levels:

  • Enable all logs:

    localStorage.debug = 'kigo-sdk:*';
    
  • Enable only error logs:

    localStorage.debug = 'kigo-sdk:error';
    
  • Disable all logs:

    localStorage.debug = '';
    

After setting the localStorage.debug value, refresh the page for the changes to take effect.

For more detailed information on how to use the debug package, please refer to the debug documentation.


What’s Next