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

winston-client

v2.1.9

Published

A versatile logging utility based on winston, featuring daily rotating log files and easy configuration for both file and console logging.

Downloads

269

Readme

winston-client

winston-client is a configurable logging utility built on top of the winston library with support for daily rotating log files. This module is designed to be configured once and used throughout your application, providing a consistent and easy-to-use logging setup.

Installation

Install the package using npm:

npm install winston-client

Usage

1. Configure the Logger

Configure the logger in your main entry file (e.g., app.js). This setup ensures that the logger is properly configured before being used in other parts of your application.

import { configureLogger } from 'winston-client';

// User configuration
const userConfig = {
    createFileLogs: true,        // Set to false to disable file logging
    includeConsole: true,        // Set to false to disable console logging
    logDir: 'custom-logs',       // Directory for log files
    env: 'production',           // Environment ('development', 'production', etc.)
    mainFilename: import.meta.url.slice(7),  // Main filename for label formatting
};

configureLogger(userConfig);

2. Use the Logger

In other files, import the getLogger function to access the configured logger instance.

import { getLogger } from 'winston-client';

const LOG = getLogger();

LOG.info('This is an info log message');
LOG.error('This is an error log message');
LOG.debug('This is a debug log message');
LOG.warn('This is a warning log message');
LOG.silly('This is a silly log message');

Configuration Options

The configureLogger function accepts a configuration object with the following options:

  • createFileLogs (boolean): Whether to create daily rotating log files. Default is true.
  • includeConsole (boolean): Whether to log to the console. Default is true.
  • logDir (string): Directory path for log files. Default is 'logs'.
  • env (string): Environment mode. Default is 'development'.
  • mainFilename (string): Main filename for labeling logs. Default is derived from import.meta.url.

Example

Here is a complete example demonstrating how to configure and use the logger:

app.js

import { configureLogger } from 'winston-client';

// User configuration
const userConfig = {
    createFileLogs: true,
    includeConsole: true,
    logDir: 'custom-logs',
    env: 'production',
    mainFilename: import.meta.url.slice(7),
};

configureLogger(userConfig);

// Your application code...

anotherFile.js

import { getLogger } from 'winston-client';

const LOG = getLogger();

LOG.info('This is an info log message');
LOG.debug('This is a debug log message');
LOG.warn('This is a warning log message');
LOG.error('This is an error log message');
LOG.silly('This is a silly log message');

Error Handling

If you try to get the logger instance before configuring it, an error will be thrown:

import { getLogger } from 'winston-client';

const LOG = getLogger(); // Error: Logger is not configured. Call configureLogger() first.

Ensure that configureLogger is called before attempting to get the logger instance.

License

This project is licensed under the ISC License.