Class

Logger

Logger(optionsopt)

A simple and customizable logger class for JavaScript applications. It allows enabling/disabling specific log levels independently. Supports debug, info, warn, and error logging with console output.

  • @example // Basic usage with defaults (all levels enabled) const logger = new Logger(); logger.debug('This is a debug message'); logger.info('This is an info message'); logger.warn('This is a warning'); logger.error('This is an error');
Constructor

# new Logger(optionsopt)

Constructor for the Logger class.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Customize which levels to show (true/false for each). Defaults: { debug: true, info: true, warn: true, error: true } Example: { debug: false, info: false } to hide debug and info.

debug boolean <optional>
true

Enable debug logs.

info boolean <optional>
true

Enable info logs.

warn boolean <optional>
true

Enable warn logs.

error boolean <optional>
true

Enable error logs.

Since:
  • 11.2025, aab

View Source tools/logger.js, line 46

Examples
// Customizing levels (e.g., hide debug and info for production-like behavior)
const logger = new Logger({ debug: false, info: false });
logger.debug('This won\'t show');
logger.info('This won\'t show');
logger.warn('This will show');
logger.error('This will show');
// Environment-based instantiation
const isDev = process.env.NODE_ENV !== 'production';
const logger = new Logger({
  debug: isDev,
  info: isDev,
  warn: true,
  error: true
});
// Dynamic level changes
const logger = new Logger();
logger.setLevels({ warn: false });
logger.warn('This won\'t show now');

  

Classes

Logger

Members

Object

# levels

View Source tools/logger.js, line 59

Methods

# debug(…args)

Logs debug information (if enabled).

Parameters:
Name Type Attributes Description
args any <repeatable>

Arguments to log.

View Source tools/logger.js, line 71

# error(…args)

Logs errors (if enabled, with error in console).

Parameters:
Name Type Attributes Description
args any <repeatable>

Arguments to log.

View Source tools/logger.js, line 101

# info(…args)

Logs general information (if enabled).

Parameters:
Name Type Attributes Description
args any <repeatable>

Arguments to log.

View Source tools/logger.js, line 81

# setLevels(newOptions)

Update levels dynamically.

Parameters:
Name Type Attributes Description
newOptions Object

Same as constructor options.

debug boolean <optional>

Update debug level.

info boolean <optional>

Update info level.

warn boolean <optional>

Update warn level.

error boolean <optional>

Update error level.

View Source tools/logger.js, line 115

# warn(…args)

Logs warnings (if enabled, with warn in console).

Parameters:
Name Type Attributes Description
args any <repeatable>

Arguments to log.

View Source tools/logger.js, line 91