CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-logform

An mutable object-based log format designed for chaining & objectMode streams.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

text-formatting.mddocs/

Text Formatting

Basic text formatting operations for messages and levels, providing simple text transformations and custom templating.

Capabilities

Align Format

Adds a tab delimiter before the message to align it in the same place.

/**
 * Creates an align format that adds tab indentation
 * @returns {Format} Align format instance
 */
function align();

Usage Examples:

const { format } = require('logform');

const alignFormat = format.align();
const result = alignFormat.transform({
  level: 'info',
  message: 'my message'
});
// Result: { level: 'info', message: '\tmy message' }

Simple Format

Creates a simple text representation of log entries in the format level: message with optional metadata.

/**
 * Creates a simple text format
 * @returns {Format} Simple format instance
 */
function simple();

The simple format produces output in this structure:

  • ${level}: ${message} if no additional metadata
  • ${level}: ${message} ${JSON.stringify(metadata)} if additional properties exist

Usage Examples:

const { format } = require('logform');
const { MESSAGE } = require('triple-beam');

const simpleFormat = format.simple();

// Basic usage
const result1 = simpleFormat.transform({
  level: 'info',
  message: 'Hello world'
});
console.log(result1[MESSAGE]); // "info: Hello world"

// With metadata
const result2 = simpleFormat.transform({
  level: 'error',
  message: 'Something failed',
  errorCode: 500,
  timestamp: '2023-01-01T00:00:00Z'
});
console.log(result2[MESSAGE]); 
// "error: Something failed {\"errorCode\":500,\"timestamp\":\"2023-01-01T00:00:00Z\"}"

Printf Format

Creates a custom logging format using a template function.

/**
 * Creates a printf-style format with custom template function
 * @param {Function} templateFn - Function that receives info object and returns formatted string
 * @returns {Format} Printf format instance
 */
function printf(templateFn);

Usage Examples:

const { format } = require('logform');

// Basic template
const myFormat = format.printf((info) => {
  return `${info.level}: ${info.message}`;
});

const result = myFormat.transform({
  level: 'info',
  message: 'Hello world'
});

// With timestamp and metadata
const detailedFormat = format.printf((info) => {
  const { level, message, timestamp, ...meta } = info;
  const metaStr = Object.keys(meta).length ? JSON.stringify(meta, null, 2) : '';
  return `[${timestamp}] ${level}: ${message} ${metaStr}`;
});

// Combined with other formats
const combinedFormat = format.combine(
  format.timestamp(),
  format.printf((info) => {
    return `${info.timestamp} [${info.level}]: ${info.message}`;
  })
);

Printf Class

The internal class used by the printf format.

/**
 * Internal Printf class that handles template formatting
 */
class Printf {
  /**
   * @param {Function} templateFn - Template function for formatting
   */
  constructor(templateFn);
  
  /** Template function that formats info objects */
  template: Function;
  
  /**
   * Transform method that applies the template
   * @param {Object} info - Log info object
   * @returns {Object} Info object with MESSAGE symbol set
   */
  transform(info);
}

docs

colorization.md

core-formats.md

data-enhancement.md

format-composition.md

index.md

json-formats.md

string-processing.md

text-formatting.md

tile.json