Logging

The SDK supports comprehensive logging. You can configure it by passing a logging object into the client initialization options.

import { MMGClient, logging } from "mobile-money-sdk";
const client = new MMGClient({
// ... credentials
logging: {
level: logging.LogLevel.Debug, // Defaults to LogLevel.Info
logger: new logging.ConsoleLogger(), // Defaults to ConsoleLogger
silent: false, // Defaults to true
}
});

Configuration Options

  • level: The verbosity of the logs (logging.LogLevel.Debug, Info, Warn, or Error).
  • logger: The logging implementation to use.
  • silent: Set to false to enable output.

Custom Loggers

To provide a custom logger, pass in an object that implements the logging.ILogger interface.

Example: Using Winston
import winston from 'winston';
import { logging } from 'mobile-money-sdk';
const winstonLogger = winston.createLogger({ /* ... config ... */ });
const logger: logging.ILogger = {
debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
info: (msg, ...args) => winstonLogger.info(msg, ...args),
warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
error: (msg, ...args) => winstonLogger.error(msg, ...args),
};
Example: Using Pino
import pino from 'pino';
import { logging } from 'mobile-money-sdk';
const pinoLogger = pino({ /* ... config ... */ });
const logger: logging.ILogger = {
debug: (msg, ...args) => pinoLogger.debug(args, msg),
info: (msg, ...args) => pinoLogger.info(args, msg),
warn: (msg, ...args) => pinoLogger.warn(args, msg),
error: (msg, ...args) => pinoLogger.error(args, msg),
};