@bro-code/logger
v2026.0.3
Published
A simple, chainable, fully customizable terminal logger with color support, config file integration, log levels, and environment-aware defaults for the @bro-code/* package ecosystem.
Downloads
771
Maintainers
Readme
@bro-code/logger
A simple, chainable, fully customizable terminal logger with color support, config file integration, log levels, and environment-aware defaults for the @bro-code/* package ecosystem.
Installation
npm install @bro-code/loggerQuick Start
import logger from '@bro-code/logger';
logger.log('Hello world');
logger.info('Server started on port 3000');
logger.debug('Processing request', 1);
logger.error('Something went wrong', 0, { bold: true });CommonJS
const logger = require('@bro-code/logger').default;
logger.log('Hello from CJS');Features
- 6 log methods —
log,info,warn,debug,error,json,code - Chainable follow-on args — each additional argument indents one more tab level
- Array support — arrays display items at the same indent level, with optional bullets or numbering
- Fully customizable — colors, styles, borders, timestamps, labels, alignment, and more
- Config file — shared
bro.config.jsonacross all @bro-code/* packages - Log levels —
silent,error,warn,info,debug,verbose - Environment-aware — auto-adjusts log level for production, development, and test
- Zero dependencies — built-in ANSI color support, no external packages
- Dual ESM/CJS — works in both module systems with full TypeScript types
Usage
Indentation (Tabs)
Every method accepts a tab parameter (second argument) that controls indentation. Each tab level is 2 spaces by default.
logger.log('no indent'); // "no indent"
logger.log('one tab', 1); // " one tab"
logger.log('two tabs', 2); // " two tabs"Chainable Follow-On Args
Additional arguments after the options parameter each increase the indent by one level:
logger.log('something', 0, null, 'like', 'this');
// something
// like
// thisArrays
When a follow-on arg is an array, each item prints at the same indent level:
logger.log('items', 0, null, ['apples', 'bananas', 'oranges']);
// items
// apples
// bananas
// orangesBullets and Numbered Lists
logger.log('shopping list', 0, { bullets: true }, ['milk', 'eggs', 'bread']);
// shopping list
// - milk
// - eggs
// - bread
logger.log('steps', 0, { numbered: true }, ['first', 'second', 'third']);
// steps
// 1. first
// 2. second
// 3. thirdJSON Output
logger.json({ name: '@bro-code/logger', version: '2026.0.0' });
// Pretty-printed, colorized JSON outputCode Output
logger.code('const x = 42;\nconsole.log(x);', 0, { codeLineNumbers: true });
// 1 const x = 42;
// 2 console.log(x);Options
Every log method accepts an options object as the third argument:
logger.log('message', tab, options, ...followOnArgs);Text Styling
| Option | Type | Description |
| --------------- | --------- | -------------------------- |
| color | string | Foreground color |
| bgColor | string | Background color |
| bold | boolean | Bold text |
| dim | boolean | Dim/faint text |
| italic | boolean | Italic text |
| underline | boolean | Underlined text |
| strikethrough | boolean | Strikethrough text |
| inverse | boolean | Swap foreground/background |
| hidden | boolean | Hidden text |
Available colors: black, red, green, yellow, blue, magenta, cyan, white, gray, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite
Available background colors: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray
Indentation
| Option | Type | Default | Description |
| --------- | -------- | ------- | ------------------------- |
| tabSize | number | 2 | Spaces per tab level |
List Formatting
| Option | Type | Default | Description |
| ------------ | --------- | ------- | -------------------------------- |
| bullets | boolean | false | Prefix array items with a bullet |
| bulletChar | string | '-' | Custom bullet character |
| numbered | boolean | false | Number array items |
Line Formatting
| Option | Type | Description |
| ----------- | -------- | --------------------------------------- |
| prefix | string | String prepended to every output line |
| suffix | string | String appended to every output line |
| separator | string | Separator between follow-on items |
Timestamp
| Option | Type | Description |
| ----------------- | --------- | ---------------------------------------------------- |
| timestamp | boolean | Show a timestamp |
| timestampFormat | string | Format: 'iso', 'locale', 'time', or custom |
Labels
| Option | Type | Description |
| ----------- | --------- | ---------------------------------------- |
| label | string | Custom label text |
| showLabel | boolean | Show/hide the method label |
| labelColor| string | Color for the label text |
Spacing
| Option | Type | Description |
| --------------- | --------- | ------------------------------- |
| newlineBefore | boolean | Blank line before log |
| newlineAfter | boolean | Blank line after log |
| padBefore | number | Number of blank lines before |
| padAfter | number | Number of blank lines after |
Border / Box
| Option | Type | Description |
| ------------- | -------- | -------------------------------------------------- |
| border | boolean| Wrap output in a border box |
| borderColor | string | Border color |
| borderStyle | string | 'single', 'double', 'round', or 'bold' |
JSON Options
| Option | Type | Default | Description |
| -------------- | --------- | ------- | ----------------------------- |
| jsonIndent | number | 2 | JSON indentation spaces |
| jsonColors | boolean | true | Colorize JSON output |
| jsonDepth | number | ∞ | Max display depth |
| jsonSortKeys | boolean | false | Sort object keys |
Code Options
| Option | Type | Default | Description |
| ----------------- | --------- | ------- | ----------------------- |
| codeLineNumbers | boolean | false | Show line numbers |
| codeBorder | boolean | false | Border around code |
| codeLanguage | string | — | Language hint |
Behavior
| Option | Type | Description |
| -------- | --------- | ------------------------------------ |
| silent | boolean | Suppress this log |
| raw | boolean | Output without formatting |
| stream | string | 'stdout' or 'stderr' |
Width / Alignment
| Option | Type | Description |
| ---------- | -------- | ------------------------------------------ |
| maxWidth | number | Max line width (wraps text) |
| align | string | 'left', 'center', or 'right' |
Configuration
bro.config.json
Create a bro.config.json file in your project root. This config is shared across all @bro-code/* packages:
{
"logger": {
"level": "debug",
"env": "development",
"tabSize": 2,
"defaults": {
"timestamp": true,
"showLabel": true
},
"methods": {
"log": { "color": "white" },
"info": { "color": "cyan" },
"debug": { "color": "gray" },
"warn": { "color": "yellow" },
"error": { "color": "red", "bold": true },
"json": { "color": "green" },
"code": { "color": "yellow" }
}
}
}Environment Variables
| Variable | Description |
| --------------- | ------------------------------------------------ |
| BRO_LOG_LEVEL | Override log level (silent, error, warn, info, debug, verbose) |
| BRO_ENV | Override environment (production, development, test) |
| NODE_ENV | Fallback environment variable |
| NO_COLOR | Disable color output (colors are enabled by default) |
Log Levels
| Level | Shows | Default Environment |
| --------- | ---------------------------------- | ---------------------- |
| silent | Nothing | — |
| error | error | test |
| warn | error, warn | production |
| info | error, warn, info, log, json, code | — |
| debug | All of the above + debug | development |
| verbose | Everything | — |
Programmatic Configuration
import { BroLogger } from '@bro-code/logger';
const logger = new BroLogger({
level: 'debug',
tabSize: 4,
defaults: {
timestamp: true,
bold: true,
},
methods: {
error: { color: 'brightRed', border: true },
},
});API
Methods
All methods return the logger instance (this) and share the same signature:
method(message: unknown, tab?: number, options?: BroLogOptions | null, ...args: unknown[]): BroLogger| Method | Default Color | Default Label | Stream |
| -------- | ------------- | ------------- | -------- |
| log | white | — | stdout |
| info | cyan | [INFO] | stdout |
| warn | yellow | [WARN] | stderr |
| debug | gray | [DEBUG] | stdout |
| error | red | [ERROR] | stderr |
| json | green | — | stdout |
| code | yellow | — | stdout |
Properties
| Property | Type | Description |
| --------- | ---------- | ---------------------------- |
| level | LogLevel | Get/set the current log level |
| tabSize | number | Get/set the tab size |
reload()
Reload configuration from the bro.config.json file.
logger.reload();License
MIT © Bro Code Technologies
Changelog
[2026.0.3] - 2026-04-23
Fixed
- CJS build:
tsconfig.cjs.jsoncorrected to emit real CommonJS output. The previousmodule: Node16setting combined with"type": "module"caused TypeScript to emit ESM syntax (export {) intodist/cjs/, which brokerequire()in Node.js environments.
[2026.0.2] - 2026-04-19
Documentation
- Added usage examples for all options in the README
[2026.0.1] - 2026-04-19
Fixed
- Colors are now enabled by default — only
NO_COLORenv var disables them. Previously, colors were disabled whenprocess.stdout.isTTYwasfalse(e.g., spawned child processes), causing all output to appear uncolored. - Multi-line log messages now indent continuation lines by one tab level for readability.
[2026.0.0] - 2026-04-17
Added
- Initial release
- Log methods:
log,info,warn,debug,error,json,code - Chainable follow-on arguments with progressive indentation
- Array support with bullets and numbered lists
- Full text styling: color, bgColor, bold, dim, italic, underline, strikethrough, inverse
- Border/box wrapping with single, double, round, and bold styles
- Timestamps with iso, locale, and time formats
- Configurable labels per method
- Prefix/suffix per line
- Text wrapping and alignment
- JSON pretty-printing with colorized output, depth limiting, key sorting
- Code display with optional line numbers and borders
bro.config.jsonshared config file support- Environment-aware log levels (production → warn, development → debug, test → error)
BRO_LOG_LEVEL,BRO_ENV,NODE_ENVenvironment variablesNO_COLORandFORCE_COLORsupport- Dual ESM/CJS output with TypeScript declarations
- Zero runtime dependencies
