npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

structlog

v1.0.5

Published

Structured logging tool for Node.js.

Downloads

48

Readme

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. |