or run

npx @tessl/cli init
Log in

Version

Files

docs

advanced-colors.mdbackground-colors.mdbasic-colors.mdcolor-support.mdconfiguration.mdindex.mdtext-styling.md
tile.json

task.mdevals/scenario-7/

Styled Log Formatter

Build a log formatter that composes reusable style builders and applies them to level prefixes using the dependency's chainable styling system.

Capabilities

Build reusable stylers

  • Given ordered style tokens (e.g., ['bgBlue', 'white', 'bold']), makeStyler returns a function that applies the combined styles to any text without altering its spacing or newlines. @test

Format log lines with default styles

  • The formatter uses default prefix style tokens: info['cyan', 'bold'], warn['yellow', 'bold'], error['whiteBright', 'bgRed'], debug['gray']. @test
  • Calling formatLog('info', ['Server', 'ready']) returns [INFO] Server ready with only the prefix styled by the info tokens; message parts are joined with single spaces and left unstyled. @test
  • Calling formatLog('error', ['Oops']) applies the error style tokens to [ERROR] while leaving the message untouched. @test

Override level styles

  • Passing customStyles.warn overrides the warn prefix styling while other levels keep defaults; e.g., formatLog('warn', ['Disk', '80%'], { customStyles: { warn: ['bgYellow', 'black'] } }) styles [WARN] with the provided tokens and returns [WARN] Disk 80%. @test

Disable styling

  • When disableColor is true, formatted output contains no ANSI escape sequences or styling and returns plain text such as [WARN] Disk 80%. @test

Implementation

@generates

API

export type LogLevel = 'info' | 'warn' | 'error' | 'debug';

export interface FormatOptions {
  customStyles?: Partial<Record<LogLevel, string[]>>;
  disableColor?: boolean;
}

/**
 * Returns a function that applies the combined styles named in `styleNames`
 * to any provided text. When `styleNames` is empty, it returns an identity
 * function.
 */
export function makeStyler(styleNames: string[]): (text: string) => string;

/**
 * Formats a log line: styles the `[LEVEL]` prefix for the provided level,
 * joins message parts with single spaces, and honors any custom styles or
 * opt-out of colorization.
 */
export function formatLog(
  level: LogLevel,
  parts: string[],
  options?: FormatOptions
): string;

Dependencies { .dependencies }

chalk { .dependency }

Provides chainable styling builders for coloring strings.