Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

append-fs-logger

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

append-fs-logger

Straight forward zero-dependency disk logger

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

Append FS logger

Lightweight, zero dependency logger designed mostly for electron applications.

append-fs-loggerpinolog4jsbunyanwinstonlogtron
pkg size64 KB480 KB562 KB3.82 MB3.4 MB5.55 MB
bundle size12 KB97 KB100 KB17 KB203 KB170 KB
dep count08132142105

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.

FAQs

Package last updated on 04 Sep 2020

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