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

biz-log-file

v1.0.7

Published

For Log File

Downloads

10

Readme

Biz Log File

biz-log-file is a lightweight, flexible logging utility for Node.js projects, built with TypeScript. It allows you to log messages in JSON format to a specified file, automatically creating directories if they don't exist.

Installation

You can install this package via npm:

npm install biz-log-file

Features

  • Log messages of different levels (info, error, warn) in JSON format.
  • Automatically creates log files and directories if they do not exist.
  • Customizable log file names and locations.
  • Logs can handle any type of message (string, object, array, etc.).

Usage

Here is a quick guide on how to use biz-log-file in your project.

1. Import the Logger

First, import the logger into your Node.js project:

import Logger from 'biz-log-file';

2. Initialize the Logger

Create a new instance of the logger by specifying a file path for the log:

const logger = new Logger('logs/app-log.json');

If the directory (logs/) doesn't exist, it will be created automatically.

3. Log Messages

You can log different types of messages using the info(), warn(), and error() methods.

// Log a simple info message
logger.info('This is an informational message');

// Log an error message
logger.error('This is an error message');

// Log an object
logger.info({ event: 'user_signup', user: 'johndoe' });

// Log an array
logger.warn(['Warning!', 'Low disk space', 'Take action']);

4. Customize Log Levels

You can pass messages of any type (strings, numbers, objects, arrays) to the logger with different log levels:

logger.log('This is a custom log message', 'info'); // Info level
logger.log({ status: 'critical', message: 'Database error' }, 'error'); // Error level
logger.log(['Warning message', 'Potential issue detected'], 'warn'); // Warning level

Log Output Format

The logs will be saved in JSON format, each entry containing the following:

  • timestamp: The date and time when the log was created.
  • level: The log level (info, error, or warn).
  • message: The content of the log message, which can be of any type.

Example log output (app-log.json):

{
  "timestamp": "2024-09-19T10:00:00.000Z",
  "level": "info",
  "message": "This is an informational message"
}
{
  "timestamp": "2024-09-19T10:00:01.000Z",
  "level": "error",
  "message": "This is an error message"
}
{
  "timestamp": "2024-09-19T10:00:02.000Z",
  "level": "warn",
  "message": ["Warning!", "Low disk space", "Take action"]
}

API Reference

new Logger(logFileName: string)

  • logFileName: (optional) The name and location of the log file. If not provided, it defaults to log.json in the current working directory.

log(message: any, level: 'info' | 'error' | 'warn')

Logs a message with the specified log level.

  • message: Can be any type (string, object, array, number, etc.).
  • level: (optional) The log level, defaults to 'info'.

info(message: any)

Logs a message at the info level.

error(message: any)

Logs a message at the error level.

warn(message: any)

Logs a message at the warn level.

License

This project is licensed under the ISC License.