Socket
Socket
Sign inDemoInstall

logform

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logform

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


Version published
Maintainers
6
Created

What is logform?

The logform npm package is a module designed for formatting messages in logging systems, primarily used with the popular Winston logger. It provides a way to define how log messages should be formatted before they are written to a console, file, or any other transport.

What are logform's main functionalities?

Simple message formatting

This feature allows users to create custom message formats using the printf function from logform. It enables the inclusion of timestamp, label, level, and message in the log output.

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

const myFormat = printf(({ level, message, label, timestamp }) => {
  return `${timestamp} [${label}] ${level}: ${message}`;
});

// Use this format in a Winston logger

Colorizing the output

This feature provides an easy way to add color to log messages based on the log level, enhancing readability especially when viewing logs directly from consoles.

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

const colorizedFormat = colorize();
// This format can be used to add colors to different levels of log messages when used with Winston logger

Combining multiple formats

This feature allows the combination of multiple formatting methods such as adding labels, timestamps, and custom printf templates to create a highly customized log output.

const { format } = require('logform');
const { combine, timestamp, label, printf } = format;

const combinedFormats = combine(
  label({ label: 'My App' }),
  timestamp(),
  printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`)
);

// This combined format can be used in a Winston logger to provide a rich structured output

Other packages similar to logform

Keywords

FAQs

Package last updated on 10 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc