Logging

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

1import { MMGClient, logging } from "mobile-money-sdk";
2
3const client = new MMGClient({
4 // ... credentials
5 logging: {
6 level: logging.LogLevel.Debug, // Defaults to LogLevel.Info
7 logger: new logging.ConsoleLogger(), // Defaults to ConsoleLogger
8 silent: false, // Defaults to true
9 }
10});

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
1import winston from 'winston';
2import { logging } from 'mobile-money-sdk';
3
4const winstonLogger = winston.createLogger({ /* ... config ... */ });
5
6const logger: logging.ILogger = {
7 debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
8 info: (msg, ...args) => winstonLogger.info(msg, ...args),
9 warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
10 error: (msg, ...args) => winstonLogger.error(msg, ...args),
11};
Example: Using Pino
1import pino from 'pino';
2import { logging } from 'mobile-money-sdk';
3
4const pinoLogger = pino({ /* ... config ... */ });
5
6const logger: logging.ILogger = {
7 debug: (msg, ...args) => pinoLogger.debug(args, msg),
8 info: (msg, ...args) => pinoLogger.info(args, msg),
9 warn: (msg, ...args) => pinoLogger.warn(args, msg),
10 error: (msg, ...args) => pinoLogger.error(args, msg),
11};