Logger

Class Name Logger
Source logger.ts

The Logger class is used throughout the package for logging events, updates and errors. Logs can be written by classes, that inherit from the Logger class, by using the this.log function. A log level can be set by its second parameter:

   this.log('hello log', 'debug');

All log messages without a level default to level 'info'. If not configured otherwise, the following behavior is used:
  • drop all log messages but errors
  • log errors to console.error

It can be useful for analyzing issues to increase the log level. You can do this in two ways:

  • Set the environment variable DBCP_LOGLEVEL to a level matching your needs, which increases the log level for all modules and works with the default runtime. For example:
export DBCP_LOGLEVEL=info
  • When creating a custom runtime, set the logLevel property to a value matching your needs, when creating any module instance. This allows you to change log level for single modules, but requires you to create a custom runtime, e.g.:
const { ContractLoader } = require('@evan.network/dbcp');
const Web3 = require('web3');

// web3 instance for ContractLoader
const provider = new Web3.providers.WebsocketProvider({ '...' });
const web3 = new Web3(provider, null, { transactionConfirmationBlocks: 1 });

// custom log level 'info'
const contractLoader = new ContractLoader({ web3, logLevel: 'info', });

All loggers can have a custom LogLog storage where all logmessages with a given level will be stored. You can access the storage for the current logger module at the property logLog. All messages are stored with the following markup:

{
  timestamp, // current date in millis
  level, // loglevel of the message
  message // log message
}

You can configure the current LogLogLevel at the property logLogLevel at instantiation of your module.


constructor

new Logger(options);

Creates a new Logger instance.

Parameters

  1. options - LoggerOptions: options for Logger constructor.
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog

Returns

Logger instance

Example

const logger = new Logger();

log

logger.log(message, level);

log message with given level

Parameters

  1. message - string: log message
  2. level - string: log level as string, defaults to ‘info’

Example

runtime.executor.log('test', 'error');

= Additional Components =

Interfaces

LogLogInterface

A different LogLog storage can be attached to the logger instance of the module. The storage must implement the following functions (default array like instance)

export interface LogLogInterface {
  push: Function;
  map: Function;
  filter: Function;
};

Enums

LogLevel

Available LogLevels for the logger instance, free definable between error and gasLog

export enum LogLevel {
  debug,
  info,
  notice,
  warning,
  error,

  gasLog = 100,
  disabled = 999,
};