Socket
Socket
Sign inDemoInstall

@ajayos/nodelogger

Package Overview
Dependencies
8
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ajayos/nodelogger

This is a logging module that allows the user to log messages with different severity levels. The module uses the Winston logging library and allows the user to configure various options for the log files.


Version published
Maintainers
1
Created

Readme

Source

nodelogger

@ajayos/nodelogger is a Node.js module for logging messages with customizable severity levels and output formats.

@ajayos/nodelogger

Installation

To install @ajayos/nodelogger, run:

npm install @ajayos/nodelogger

Usage

First, import the module into your Node.js application:

const Logger = require("@ajayos/nodelogger");

Then, create an instance of the Logger class with the desired configuration options and start it:

const options = {
  timeZone: "Asia/Kolkata",
  hour: "numeric",
  minute: "numeric",
  hour12: true,
  filename: "logs/%DATE%.log",
  datePattern: "YYYY-MM/DD",
  zippedArchive: false,
  maxSize: "1g",
  level: "info",
};

const logger = new Logger(options);

Once the logger is started, you can log messages with the log method:

logger.error("This is an error message");
logger.warn("This is a warning message");
logger.info("This is an info message");
logger.debug("This is a debug message");
logger.fatal("This is a fatal message");

You can also log messages with the default severity level by omitting the second argument:

logger.log("This is a default message");

To log a horizontal line, use:

logger.line();

To clear screen:

logger.clear()

Example

Additional example of how to use the package can be found in the example file.

Configuration Options

The following configuration options are available for the logger:

  • timeZone (string): The timezone to use for the log file (default: 'Asia/Kolkata')
  • hour (string): The hour format to use for the log file (default: 'numeric')
  • minute (string): The minute format to use for the log file (default: 'numeric')
  • hour12 (boolean): Whether to use 12-hour format or not. 1 for true, 0 for false (default: false)
  • filename (string): The file path with %DATE% as a placeholder for the date (default: 'logs/%DATE%.log')
  • datePattern (string): The date pattern for the filename (default: 'YYYY-MM/DD')
  • zippedArchive (boolean): Whether to zip the archived files or not (default: false)
  • maxSize (string): The maximum size of each log file before rotation (default: '1g')
  • level (string): The level of the log messages (default: 'info')

Message Types

The following message types are available for the log method:

  • info (or i): Informational message (green text)
  • warn (or w): Warning message (yellow text)
  • error (or e): Error message (red text)
  • debug (or d): Debug message (magenta text)
  • fatal (or f): Fatal message (white text on red background)
  • line (or l): Horizontal line (cyan text)

Output Format

The output format for each message type is as follows:

  • Informational message (green text): [timestamp] [*]> message
  • Warning message (yellow text): [timestamp] [!]> message
  • Error message (red text): [timestamp] [x]> message
  • Debug message (magenta text): [timestamp] [*]> message
  • Fatal message (white text on red background): [timestamp] [!]> message
  • Horizontal line (cyan text): >-----------------------------<

License

@ajayos/nodelogger is released under the Apache-2.0 License.


Keywords

FAQs

Last updated on 30 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc