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

pysaka

v1.0.5

Published

Async threaded logger

Downloads

21

Readme

Another one?

A logger to offload the main thread of the main process in order not to affect performance.

Why?

What do you need from a logger in Node.js world?

Obvious things:

  • it must by async one (but async is very vague term)
  • it does log what you ask with any number of arguments
  • it does not loose logs
    • won't loose it even if the destination (like stdout) is unavailable temporarily
  • it supports json format (surprisingly not all of them do) Major one:
  • it does not affect performance of the main process!

It is not BLAZINGLY fast logger because not that characteristic must be a key. Look, you should do not care about speed of logging your messages, but you do care about speed/performance of your main process.

Pysaka does not eat/steal CPU time of your main thread of the main process. It delegates as much as possible, even serialization of a log message, to separate worker thread. It utilizes streams to the full because it's cheap from CPU & RAM perspective, and their are awesome in Node.js. You are more than welcome to review the code base (it's tiny).

Does do what I want

So open an issue on github and I will code it for you if it makes sense.

Description

This logger is about logging your messages using streams via a separate Worker in order to offload the main thread, so even a serialization of log messages happen in the worker (however postMessage copying takes its price still).

Features

to create an instance of the logger: new PysakaLogger();

the constructor accepts such object as a param

export type PysakaLoggerParams = {
    destination?: DestinationType;
    fallbackSupport?: boolean;
    severity?: SeverityLevelEnum;
    format?: PrintFormatEnum;
    name?: string;
    debugLogs?: boolean;
    tempDirPath?: string;
};

destination - must be Writable stream! Mostly it's process.stdout, or file descriptor with write access.

fallbackSupport - flag which identifies is logs backup needed in case if destination is not available temporarily. It preserves logs in the temporary file until your main code repairs the destination. Useful much if destination is Socket which points to another server.

severity - aka log level: 0 - debug, 1 - info, 2 - warn, 3 - error, 4 - fatal

format - two options: "json" or "text". JSON is for exporting and performance, text is for human readability, with colors.

name - name of the logger. optional

debugLogs - flag which identifies do we need to log also debug logs of the logger itself. Internal usage mostly

tempDirPath - a path to the temporary dir where logs will be stored if the destination is not available temporarily. Makes sense only if fallbackSupport is true.

How to install?

npm i pysaka

How to use?

"Usual" code example:

import PysakaLogger from 'pysaka';

const logger = new PysakaLogger();

// log your stuff

// in the end, please, close it
// otherwise it will prevent the main process to be closed
logger.close();
// or sync way
logger.closeSync();

Key method logger.write()

logger<write>('Hello world!');

or

logger<write>('Hello world!', 'error message');

or

logger<write>('Hello world!', { some: 'data' });

you are not obliged to specify the first argument as string however it's advised to do, especially if you use 'text' format (for better formatting).

where is any of the following methods:

logger.debug('Hello world!');
logger.info('Hello world!');
logger.log('Hello world!');
logger.warn('Hello world!');
logger.error('Hello world!');
logger.fatal('Hello world!'); 

Voilà !