A lightweight structured logging tool for Node.js without any dependencies

Overview

structlog

A lightweight structured logging tool for Node.js without any dependencies.

Example

By default this tool will generate logs like the following:

2022-03-09T19:57:48.962Z [error] i'm an error [/structlog/foo.js:5] thread=MAIN logId=017f705b-4200-0002-1101-720541fa117c 
2022-03-09T19:57:48.963Z [warn] i'm a warning [/structlog/foo.js:6] thread=MAIN logId=017f705b-4200-0000-e4a6-f1df2ca4f248

However, you can configure both the log and timestamp formats.

Usage

To use this logging tool, all you need to do is install it:

yarn add structlog

And use it like so:

import { logger } from 'structlog'

logger.error('error!')

Importing logger will give you a ready-made instance of StructuredLogger with the default config, so you don't need to instantiate a new logger instance each time or pass down references to an instance.

However, you can configure options by instantiating StructuredLogger yourself, like so:

import { StructuredLogger } from 'structlog'

const logger = new StructuredLogger({ timestampFormat: 'unix' })

Options

You can configure the following options by passing them in an object as a parameter when creating StructuredLogger :

Option Default value Accepted values Description
timestampFormat 'iso' 'iso' , 'gmt', 'unix', 'timestring' ,'localestring' Timestamp format to use.
logFormat '{timestamp} [{type}] {message} [{path}] {tags}' Any string Log format to use {} to define variables. Accepted variables: timestamp, type, message, path, tags.
pathFormat '{filePath}:{lineNumber}' Any string Format to use for the path component of the log. Use {} to define variables. Accepted variables: filePath, lineNumber, functionName, methodName, typeName.
useColors false true, false Whether logs should be printed with colors according to the type (e.g. error = red).
useThreadTagsExtension false true, false An extension that automatically adds a thread tag to the log specifying what thread the log happened in.
useLogIdExtension false true, false An extension that automatically adds a logId tag to the log, with a unique ID as its value.
pathStackDepth 0 Any number (Advanced) Level of depth to determine the path portion of the log from. For example, if you write a wrapper over the logger, set this to 1 so that the path will reflect the code that called your wrapper, rather than the wrapper itself.
You might also like...

danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.

danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.

Danfojs: powerful javascript data analysis toolkit What is it? Danfo.js is a javascript package that provides fast, flexible, and expressive data stru

Dec 29, 2022

A tiny, reactive JavaScript library for structured state and tabular data.

A JavaScript library for structured state. Using plain old JavaScript objects to manage data gets old very quickly. It's error-prone, tricky to track

Jan 1, 2023

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript ⚡️ Made with developer experience first ESLint + Prettier + Lint-Staged + VSCode setup

Nov 28, 2022

API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

🍕 Open Sauced Nest Supabase API 🍕 The path to your next Open Source contribution 📖 Prerequisites In order to run the project we need the following

Dec 18, 2022

Lazy minting of ERC721 NFTs using EIP712 standard for typed, structured data. ✨

ERC721 - Signature minting Lazy minting of ERC721 NFTs using EIP712 standard for typed, structured data. ✨ How it works Lazy minting or Signature mint

Oct 20, 2022

jQuery UI widget for structured queries like "Contacts where Firstname starts with A and Birthday before 1/1/2000 and State in (CA, NY, FL)"...

jQuery UI widget for structured queries like

Structured-Filter · Structured-Filter is a generic Web UI for building structured search or filter queries. With it you can build structured search co

Jan 6, 2023

Stacks Voice is a reference project that builds on the SIP018 signed structured data standard to create an accountless internet forum.

Stacks Voice Stacks Voice is a reference project that builds on the SIP018 signed structured data standard to create an accountless internet forum. Th

Dec 21, 2022

A PostgreSQL client with strict types, detailed logging and assertions.

A PostgreSQL client with strict types, detailed logging and assertions.

Slonik A battle-tested PostgreSQL client with strict types, detailed logging and assertions. (The above GIF shows Slonik producing query logs. Slonik

Jan 3, 2023

Clear console logging for every browser

Clear console logging for every browser

Console.log wrapper Safe, clear console logging for every browser Log to the console — even legacy browsers without a console. Just pass any data to l

Sep 24, 2022

Tritan is a Discord.js bot that has many general-purpose features such as logging, moderation, image manipulation, music, and much more!

Tritan Bot Tritan Bot is a Discord Verified general purpose bot built with discord.js and express (yes, it has a dashboard included). Please read thro

Jul 3, 2022

Full logging system using the djs library (v13.6.0)

Loggin-system-djs-v13.6 Full logging system using the djs library (v13.6.0) NOW ONTO MULTIPLE DISCLAIMERS: ◻ It is crucial that you first understand t

Aug 26, 2022

Tritan is a Discord.js bot that has many general-purpose features such as logging, moderation, image manipulation, music, and much more!

Tritan Bot Tritan Bot is a Discord Verified general purpose bot built with discord.js and express (yes, it has a dashboard included). Please read thro

Nov 19, 2022

Unified JavaScript logging system. KISS, light and library free.

Logger.js Logger.js is a JavaScript ES6 module that offers a unified console output across Firefox and Chromium based browsers. It handles standard er

Oct 1, 2020

NatsirtMC is a lightweight app allowing you to connect to any Minecraft server without having Minecraft open

NatsirtMC the only way to grind without grinding NatsirtMC is a lightweight app allowing you to connect to any Minecraft server without having Minecra

Dec 26, 2022

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

Aug 25, 2022

A tool that enables developers to connect multiple applications without the need to develop any interface.

Flooq A tool that enables developers to connect multiple applications without the need to develop any interface. Environments Env Service Status stagi

Jul 1, 2022

1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.

JavaScript Templates Contents Demo Description Usage Client-side Server-side Requirements API tmpl() function Templates cache Output encoding Local he

Jan 3, 2023

A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

Instagram Without APIs Instagram Scraping in August 2022, no credentials required This is a Node.js library, are you looking for the same in PHP? go t

Dec 29, 2022
Comments
  • refactor(colors): remove colors dep

    refactor(colors): remove colors dep

    • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

    • What is the current behavior? (You can also link to an open issue here)

    • What is the new behavior (if this is a feature change)?

    • Other information:

    opened by yakkomajuri 0
Owner
Yakko Majuri
Most often writing code, sometimes writing articles.
Yakko Majuri
Clear console logging for every browser

Console.log wrapper Safe, clear console logging for every browser Log to the console — even legacy browsers without a console. Just pass any data to l

Craig Patik 407 Sep 24, 2022
A small logging proxy server for intercepting and logging code completion requests from copilot.

PilotWatch PilotWatch is a small logging proxy server written in node.js for intercepting and logging code completion requests from Github's Copilot.

John Robinson 7 May 8, 2023
:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods

loglevel Don't debug with logs alone - check out HTTP Toolkit: beautiful, powerful & open-source tools for building, testing & debugging HTTP(S) Minim

Tim Perry 2.3k Jan 6, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
NodeJS library without any external dependencies to check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

free-proxy_checker NodeJS library WITHOUT any external dependencies to: download free proxies; check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

antoine vastel 15 Nov 6, 2022
🚀 Scroll Follow Tab is a lightweight javascript library without jQuery, no dependencies.

Scroll Follow Tab is a lightweight javascript library without jQuery, no dependencies. It is used to make scrollspy effect for your menu, table of contents, etc. Only 21.7Kb.

Hieu Truong 11 Jun 20, 2022
Node WebStation is a powerful tool designed for developers allowing them to create advanced web sockets for any use all without having the requirement to code.

Node WebStation Node WebStation is a powerful tool designed for developers to use to create an advanced WebStation for any use all without not having

null 2 Jun 4, 2022
Calculating Pi number without limitation until 10k digits or more in your browser powered by JS without any third party library!

PI Calculator Web JS (Online) Calculating Pi number without limitation until 10k digits or more in your browser powered by JS without any third party

Max Base 6 Jul 27, 2022