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

logzen

v0.3.10

Published

An easy to use utility for logging

Downloads

12

Readme

LogZen

Logzen is a simple and flexible logging library for Javascript that provides easy-to-use logging functionality with customizable log levels and the ability to output logs to different streams and consoles.

Documentation

Installation

You can install Logzen using npm:

npm install logzen

Usage

To use Logzen in your project, you need to import the Logger class from the Logzen package:

import { Logger } from 'logzen';

Basic Logging

Create a new Logger instance to start logging:

const logger = new Logger();

logger.log('This is a log message.');
logger.warn('This is a warning message.');
logger.error('This is an error message.');
logger.debug('This is a debug message.');

Customizing Log Levels

You can customize the log levels by setting the attachGlobalConsole option to false and manually attaching the console with custom log levels:

import { Logger, LogLevel } from 'logzen';
const logger = new Logger({ attachGlobalConsole: false });

// Attach console with custom log levels
logger.attach(console, LogLevel.WARN, LogLevel.ERROR);

logger.error('This message will be sent to the console.');
logger.log('This message will not be sent to the console!');

Logging to Files

Logzen supports logging to files by attaching file streams to the Logger instance. This allows you to send log entries with specific log levels to separate log files.

import { Logger, LogLevel } from 'logzen';
import fs from 'fs';

// Create a writable stream to a log file
const logFileStream = fs.createWriteStream('app.log', { flags: 'a' });
const errorFileStream = fs.createWriteStream('error.log', { flags: 'a' });

// Create the Logger instance
const logger = new Logger({ attachGlobalConsole: false });

// Attach the file stream with specific log levels
logger.attach(logFileStream, LogLevel.LOG, LogLevel.INFO);
logger.attach(errorFileStream, LogLevel.WARN, LogLevel.ERROR);

logger.log('This log message will be written to the app.log file.');
logger.error('This error message will also be written to the error.log file.');

Detaching Streams and Consoles

You can detach streams and consoles from the Logger using the detachStream and detachConsole methods:

const logger = new Logger();

// Detach streams and Console objects
logger.detach(stream, LogLevel.LOG, LogLevel.WARN);
logger.detach(console);

Attaching Consoles

You can also attach Console objects to the Logger instance to output logs to the console. This is useful if you have multiple consoles and want to output to all of them.

const logger = new Logger({ attachGlobalConsole: false });

logger.attach(console, LogLevel.WARN, LogLevel.ERROR);

logger.log('This log message will be not sent to the console.');
logger.error('This error will be sent to the console!');

Retaining Logs

By default, logs are retained in memory. You can disable log retention by setting the retainLogs option to false. Note that if you disable log retention, calling a Logger's toString method will return an empty string.

const logger = new Logger({ retainLogs: false });

logger.log('This log message will not be retained in memory.');
logger.warn('This warning message will also not be retained.');

Default log levels for attaching and detaching

When attaching a stream or console without specifying log levels, all will be attached. Likewise, when detaching, the stream or console will be completly removed.

FAQs

None yet!