Debug Utilities API reference for debugging, logging, and error handling utility functions bug API Reference
Categories

Debug Utilities

The Debug utilities provide functions for logging, debugging, and enhanced error handling in JavaScript.

Functions

log

function log(message, level = 'log', { namespace = '', data = undefined, color = 'inherit', timestamp = false, format = 'standard', consoleMethod = null, silent = false, title = toTitleCase(namespace), showTitle = true, titleColor = null } = {})

A flexible logging utility with formatting, namespacing, and multiple output options. Supports colored output, timestamps, structured JSON format, and configurable titles.

Parameters

NameTypeDescription
messagestringThe message to log
levelstringLog level (‘debug’, ‘log’, ‘info’, ‘warn’, ‘error’)
optionsobjectOptional configuration
Options
NameTypeDefaultDescription
namespacestringNamespace for grouping related logs (used as default title)
dataarrayundefinedAdditional data to include with the log message
colorstring’inherit’Text color for the message
timestampbooleanfalseWhether to include timestamp in the output
formatstring’standard’Output format (‘standard’ or ‘json’)
consoleMethodstringnullOverride the console method used for output
silentbooleanfalseSuppress all output when true
titlestringtoTitleCase(namespace)Title/label to display before the message
showTitlebooleantrueWhether to show the title/label
titleColorstringnullColor for the title/label (defaults to level color)

Returns

This function does not return a value.

Example

import { log } from '@semantic-ui/utils';
// Basic usage
log('Application started', 'info');
log('Debug information', 'debug');
// With namespace and data
log('User login successful', 'info', {
namespace: 'UserService',
data: [{ userId: 123, timestamp: new Date() }]
});
// JSON format for structured logging
log('API response received', 'info', {
format: 'json',
namespace: 'ApiClient',
timestamp: true,
data: [{ status: 200, endpoint: '/api/users' }]
});
// Custom styling
log('Important notice', 'warn', {
title: 'NOTICE',
titleColor: '#FF6B35',
timestamp: true
});

fatal

function fatal(message, { errorType = Error, metadata = {}, onError = null, removeStackLines = 1 } = {})

Throws an error with enhanced control over the error type, metadata, and stack trace.

Asynchronous Error Throwing This function uses queueMicrotask to throw the error asynchronously, allowing the current execution context to complete.

Parameters

NameTypeDescription
messagestringThe error message
optionsobjectOptional configuration
Options
NameTypeDefaultDescription
errorTypefunctionErrorThe type of error to throw
metadataobjectAdditional data to attach to the error
onErrorfunctionnullCallback to execute before throwing the error
removeStackLinesnumber1Number of stack trace lines to remove

Example

import { fatal } from '@semantic-ui/utils';
try {
fatal("Something went wrong", {
errorType: TypeError,
metadata: { code: "ERR_001" },
onError: (err) => console.log("Error occurred:", err.message)
});
} catch (error) {
console.error(error);
}
Previous
Dates
Next
Environment