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

append-fs-logger

v2.0.0

Published

Straight forward zero-dependency disk logger

Downloads

1

Readme

Append FS logger

Lightweight, zero dependency logger designed mostly for electron applications.

| | append-fs-logger | pino | log4js | bunyan | winston | logtron | |--------|:------------------:|:------:|:---------:|:--------:|:---------:|:--------:| |pkg size| 64 KB | 480 KB | 562 KB | 3.82 MB | 3.4 MB | 5.55 MB | |bundle size| 12 KB | 97 KB | 100 KB | 17 KB | 203 KB | 170 KB | |dep count| 0 | 8 | 13 | 21 | 42 | 105 |

Example

const path = require('path')
const MainLogger = require('append-fs-logger')

const fileName = path.join(__dirname, 'logs.nldj')
const logger = new MainLogger('my-app', {
  fileName: fileName,
  console: true
})

logger.info(msg, { extra: 'info' })
logger.warn(msg, { fullNested: { json: true } })
logger.error(msg, { fieldA: 'some info', err: err })

Motivation

When doing logging in an electron app we want different defaults then the logging behavior of a long running nodeJS server on server hardware like EC2.

The electron app runs on a users computer and we cannot use features like ElasticSearch or logrotate.

The features we want for a logger on a users computer is to log to DISK in a bounded fashion. This logger will write at most 32Mb to disk and will truncate it's own logfile to keep it below 32Mb.

If a user of your electron app submits a bug you can ask them to upload the logfile written to disk.

This logger always supports writing to browser console and stdout in the main process for local development convenience but this should be disabled in the packaged application.

Documentation

Logger supports log.info() ; log.warn() & log.error().

Each level method (info(), warn(), error(), etc.) takes a string and an object of more information.

The logging methods also return a promises that resolves when the logline has been flushed to disk.

The string message argument to the level method should be a static string, not a dynamic string. This allows anyone analyzing the logs to quickly find the callsite in the code and anyone looking at the callsite in the code to quickly grep through the logs to find all prints.

The object information argument should be the dynamic information that you want to log at the callsite. Things like an id, an uri, extra information, etc are great things to add here. You should favor placing dynamic information in the information object, not in the message string.

See bunyan level descriptions for more / alternative suggestions around how to use levels.

logger.info(message, information)

info() is meant to used when you want to print informational messages that concern application or business logic. These messages should just record that a "useful thing" has happened.

You should use warn() or error() if you want to print that a "strange thing" or "wrong thing" has happened

logger.warn(message, information)

warn() is meant to be used when you want to print warning messages that concern application or business logic. These messages should just record that an "unusual thing" has happened.

If your in a code path where you cannot recover or continue cleanly you should consider using error() instead. warn() is generally used for code paths that are correct but not normal.

logger.error(message, information)

error() is meant to be used when you want to print error messages that concern application or business logic. These messages should just record that a "wrong thing" has happened.

You should use error() whenever something incorrect or unhandlable happens.

If your in a code path that is uncommon but still correct consider using warn() instead.