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

super-logger-winston

v1.0.2

Published

This will be used for logging purpuse

Downloads

7

Readme

Node.js Logger with Daily Rotation

A flexible and efficient logging solution for Node.js applications, built using winston, offering daily log rotation, compression, custom log levels, and more.

Features

  • Daily Log Rotation: Automatically rotates log files daily.
  • Compression: Compresses old log files to save disk space.
  • Custom Log Levels: Supports multiple log levels (info, error, warn, debug, etc.).
  • Console Logging: Optionally logs to both files and the console.
  • Environment Variables Support: Control logging behavior (log level, file size, retention) via environment variables.
  • Supports ES6 and CommonJS: Works with both import (ES6) and require (CommonJS).

Installation

To install the logger package, run:

npm install super-logger-winston
npm i super-logger-winston

Usage

1. ES6 Modules (Using import)

import Logs from 'super-logger-winston';

const loggingConsole = true  // default false
const loggingPath = './logs/application'
const logger = new Logs( loggingPath , loggingConsole);

// Log info
logger.info('Application started');
logger.info({server:'Server started successfuly'});     // it accept both string and object

// Log errors
logger.error({ error: 'Unhandled exception', stackTrace: 'stack trace here' });

2. CommonJS Modules (Using require)

const Logs = require('super-logger-winston');

const loggingConsole = true  // default false
const loggingPath = './logs/application'
const logger = new Logs( loggingPath , loggingConsole);

// Log info
logger.info('Application started');
logger.info({server:'Server started successfuly'});     // it accept both string and object


// Log errors
logger.error({ error: 'Unhandled exception', stackTrace: 'stack trace here' });

Constructor Parameters

  • filePath: Base path for storing log files (e.g., ./logs/application). Log files will be named with the pattern application-YYYY-MM-DD.log.
  • loggingConsole: (Optional) If true, logs will be output to both files and the console.

Example

const logger = new Logs('./logs/app', true);

logger.info('Server started successfully');
logger.info({Server:'Server started successfully'});
logger.warn('Low disk space');
logger.error('Failed to connect to database');

Log Levels

The logger supports the following log levels:

  • info: General operational messages (e.g., "Server started").
  • error: Critical issues that require immediate attention.
  • warn: Non-critical issues, potential problems (e.g., "Low disk space").
  • debug: Detailed debugging information for development.

Example Usage

logger.info('Application started');
logger.warn('User has low storage space');
logger.error('Failed to connect to database');
logger.debug('Database query executed successfully');

// Json format

logger.info({server:'Application started'});
logger.warn({DiskStorage:'User has low storage space'});
logger.error({DBConnection:'Failed to connect to database'});
logger.debug({DBConnection:'Database query executed successfully'});

Log Rotation and File Management

  • Log Rotation: Logs are rotated daily and saved with a timestamped filename, e.g., application-2024-09-21.log.
  • Compression: Old logs are compressed into .gz format, e.g., application-2024-09-20.log.gz.
  • Retention: Configure how long to keep old log files using the maxFiles option.

Environment Variables

You can control various logger behaviors using environment variables:

| Variable | Description | Default Value | |----------------|-----------------------------------------------------|---------------| | LOGGING_LEVEL | Sets the log level (info, warn, error, debug) | 'debug' | | MAX_FILE_SIZE | Maximum size for each log file before rotation | '200m' | | FILE_ROTATION_PERIOD | Maximum number of days to retain old log files | '14d' |

Example:

LOGGING_LEVEL=debug MAX_FILE_SIZE=5m FILE_ROTATION_PERIOD=7d node your-app.js

Code with Environment Variables

const loggingConsole= true
const logger = new Logs('./logs/app', loggingConsole);

logger.info('Server started in debug mode');

License

This project is licensed under the MIT License. See the LICENSE file for more details.