NPM package for browser debugging with customizable logging levels (log, warn, error, debug).
Lightweight and easy to use.
Features:
- No dependencies — pure TypeScript only;
- Size ~3.5 kB — minimal impact on your bundle;
- SonarQube
ARating — highest level of code quality and reliability; - Console output styling — color formatting for quick identification;
- Global storage — access debug data via
window; - Flexible configuration — logging levels, styles, aliases, inheritance support.
English, Español, Deutsch, 中文, Русский
npm install debug-webyarn add debug-webPriority (from lowest to highest):
debug(0) — debug information (console.debug);log(1) — basic messages (console.log)info(2) — informational messages (console.info)warn(3) — warnings (console.warn)error(4) — errors (console.error)
ℹ️ Custom levels: any string values (e.g., success, focus) will be processed with specific behavior:
- Regular custom levels (without underscore prefix) use the
infolevel - Levels starting with underscore (e.g.,
_info,_error) use thedebuglevel Both can have their own styles.
| Parameter | Type | Default | Description |
|---|---|---|---|
app |
string | null |
'debug' |
Unique application name to separate data |
level |
DebugLogLevel |
'log' |
Minimum logging level (messages below this level are not output) |
prop |
string | null |
'debug' |
Global variable name to access data (null — do not create) |
data |
Record<string, unknown> |
undefined |
Initial debug data |
local |
boolean |
false |
Save level in localStorage (otherwise sessionStorage) |
native |
boolean |
false |
Use native console methods (without styles) |
onLog |
(level, attrs) => void |
undefined |
Function called after each log |
title |
Record<string, string> |
undefined |
Titles for custom log levels |
alias |
Record<string, DebugLogLevel> |
see below | Custom aliases for createDebug |
style |
Record<DebugLogLevel, string> |
see below | CSS styles for log levels |
type DebugLogLevel = 'debug' | 'log' | 'info' | 'success' | 'warn' | 'error' | string;| Level | Style (CSS) |
|---|---|
info |
background-color: #155adc; color: #fff; padding: 2px; border-radius: 3px |
mark |
background-color: #695aff; color: #fff; padding: 2px; border-radius: 3px |
success |
background-color: #13a10e; color: #fff; padding: 2px; border-radius: 3px |
focus |
background-color: #881798; color: #fff; padding: 2px; border-radius: 3px |
alert |
background-color: #ffa500; color: #fff; padding: 2px; border-radius: 3px |
danger |
background-color: #dc143c; color: #fff; padding: 2px; border-radius: 3px |
d → debug, l → log, i → info, w → warn, e → error
// debug.ts
import { DebugWeb } from 'debug-web';
export const debug = new DebugWeb({
app: 'my-app',
level: process.env.NODE_ENV === 'development' ? 'log' : 'error',
data: { version: APP_VERSION },
alias: { s: 'success', f: 'focus' },
local: true,
});Creates a proxy with aliases and custom level support.
<T extends typeof DebugWeb>(options?: CreateDebugOptions, DebugClass?: T) => CustomLogLevels & InstanceType<T>;| Level | Type |
|---|---|
debug |
(message?: unknown, ...attrs: unknown[]) => void |
log |
(...attrs: unknown[]) => void |
info |
(...attrs: unknown[]) => void |
warn |
(...attrs: unknown[]) => void |
error |
(...attrs: unknown[]) => void |
group |
(open?: boolean, level?: DebugLogLevel, ...attrs: unknown[]) => void |
groupEnd |
(level?: DebugLogLevel) => void |
dir |
(value: unknown, options?: unknown) => void |
dirxml |
(...attrs: unknown[]) => void |
trace |
(...attrs: unknown[]) => void |
table |
(data: unknown, properties?: string[]) => void |
count |
(label?: string) => void |
countReset |
(label?: string) => void |
time |
(label?: string) => void |
timeLog |
(label?: string, ...attrs: unknown[]) => void |
timeEnd |
(label?: string) => void |
| Method | Type | Comment |
|---|---|---|
set |
(data: DebugWebData, storage?: boolean) => void |
Saves debug data (merges). If storage=true — saves to sessionStorage |
get |
(storage?: boolean) => DebugWebData | undefined |
Returns a copy of data. If true is passed, retrieves from sessionStorage |
dump |
(keys: string[], options?: DumpOptions) => void |
Outputs data as a table (ignores logging levels) |
type DebugWebData = Record<string, unknown>
type DumpOptions = {
level?: DebugLogLevel;
title?: string | ((data: DebugWebData) => string);
open?: boolean;
}| Method | Type | Comment |
|---|---|---|
level (getter) |
DebugLogLevel |
Get the current logging level |
level (setter) |
DebugLogLevel |
Set the current logging level |
| Method | Type | Comment |
|---|---|---|
style (getter) |
() => DebugWebStyle |
Get the current styles map |
style (setter) |
(styles: DebugWebStyle) => void |
Update the styles map (will be merged) |
type DebugWebStyle = Record<DebugLogLevel, string | undefined>Save any data and view it in the console:
debug.set({ error: null, user: { id: 1, name: 'John' } });Data is accessible via window[prop] (default is debug).
Type into the browser console:
debug // { error: null, user: {...}, setLevel: f }
debug.setLevel() // change logging levelIf you find this library useful, consider supporting its development:
MIT © Karlen Pireverdiev

