AR.IO LogoAR.IO Documentation

Logging

The library uses a lightweight console logger by default for both Node.js and web environments. The logger outputs structured JSON logs with timestamps. You can configure the log level via setLogLevel() API or provide a custom logger that satisfies the ILogger interface.

Default Logger

import { Logger } from '@ar.io/sdk';

// set the log level
Logger.default.setLogLevel('debug');

// Create a new logger instance with a specific level
const logger = new Logger({ level: 'debug' });

Custom Logger Implementation

You can provide any custom logger that implements the ILogger interface:

import { ARIO, ILogger } from '@ar.io/sdk';

// Custom logger example
const customLogger: ILogger = {
  info: (message, ...args) => console.log(`[INFO] ${message}`, ...args),
  warn: (message, ...args) => console.warn(`[WARN] ${message}`, ...args),
  error: (message, ...args) => console.error(`[ERROR] ${message}`, ...args),
  debug: (message, ...args) => console.debug(`[DEBUG] ${message}`, ...args),
  setLogLevel: (level) => {
    /* implement level filtering */
  },
};

// Use custom logger with any class
const ario = ARIO.mainnet({ logger: customLogger });

// or set it as the default logger in the entire SDK
Logger.default = customLogger;

Winston Logger (Optional)

For advanced logging features, you can optionally install Winston and use the provided Winston logger adapter:

yarn add winston
import { ARIO, WinstonLogger } from '@ar.io/sdk';

// Create Winston logger with custom configuration
const winstonLogger = new WinstonLogger({
  level: 'debug',
});

// Use with any class that accepts a logger
const ario = ARIO.mainnet({ logger: winstonLogger });

// or set it as the default logger in the entire SDK
Logger.default = winstonLogger;

You can easily integrate other popular logging libraries:

// Bunyan example
import { ARIO, ILogger } from '@ar.io/sdk';
import bunyan from 'bunyan';

const bunyanLogger = bunyan.createLogger({ name: 'ar-io-sdk' });
const adapter: ILogger = {
  info: (message, ...args) => bunyanLogger.info({ args }, message),
  warn: (message, ...args) => bunyanLogger.warn({ args }, message),
  error: (message, ...args) => bunyanLogger.error({ args }, message),
  debug: (message, ...args) => bunyanLogger.debug({ args }, message),
  setLogLevel: (level) => bunyanLogger.level(level),
};

const ario = ARIO.mainnet({ logger: adapter });

// or set it as the default logger in the entire SDK
Logger.default = adapter;

How is this guide?