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

ts-logger-node

v2.0.7

Published

TS-Logger-Node is a TypeScript library that provides logging functionality with customizable styles and log file management. It allows you to print log messages to the console with various text and background styles, as well as append them to separate log

Downloads

3

Readme

TS-Logger-Node

ts-logger-node is a Node.js logging package that provides a simple yet powerful logging mechanism with customizable log file paths and console output styles. This package is written in TypeScript and comes with type definitions for enhanced development experience.

Installation

To install ts-logger-node, you can use npm or yarn:

npm install ts-logger-node

or

yarn add ts-logger-node

Usage

Importing the Logger

To use the logger, import it into your project:

import Logger from "ts-logger-node";

Logging Messages

You can log messages with different types: ERROR, GENERAL, or HEADER. The print method is used to log messages, and it takes three arguments:

  • msg (string): The log message you want to write.
  • type (LogType): The log type, which can be "ERROR", "GENERAL", or "HEADER".
  • options (optional object): Additional options for styling the console output. It contains a style property (string) that accepts ANSI escape sequences for colors and other text styles.
Logger.print("This is an error message", "ERROR");
Logger.print("This is a general message", "GENERAL", {
  style: textStyles.FgGreen,
});
Logger.print("This is a header message", "HEADER", {
  style: textStyles.BgBlue,
});

Customizing Log File Paths

By default, the log files are stored in the "logs" directory with filenames "general.log" and "error.log". You can customize these file paths using the paths setter:

Logger.paths = {
  general: {
    dir: "custom-logs/",
    fileName: "custom-general",
    fileExt: ".log",
  },
  error: {
    dir: "custom-logs/",
    fileName: "custom-error",
    fileExt: ".log",
  },
};

Log Return Types

The print method returns a LogReturnType that indicates the status of the log operation. The possible return types are:

  • "SUCCESS_LOG": The log message was successfully written to the log file and console.
  • "ERROR_LOG": The log message was successfully written to the error log file, and the error message was printed to the console.
  • "FILE_WRITE_ERROR": There was an error writing the log message to the log file.

Available Text Styles

The package also exports a textStyles object, which provides a set of ANSI escape sequences for styling the console output. You can use these styles in the options.style property to customize the appearance of log messages.

import Logger, { textStyles } from " ts-logger-node";

Logger.print("This text will be blue!", "GENERAL", {
  style: textStyles.FgBlue,
});
Logger.print("White text on red background!", "GENERAL", {
  styles: {
    style: textStyles.BgRed + textStyles.FgWhite,
  },
});

Next Usability

Implimenting ts-logger-node can only be done in server-components currently. In order to use Logger, or any other package that requries 'fs', in a NextJS app the a next.config file must include the following:

const nextConfig = {
  webpack5: true,
  webpack: (config) => {
    config.resolve.fallback = { fs: false };

    return config;
  }
}

Contributing

If you find any issues with ts-logger-node or want to contribute improvements or new features, please feel free to open an issue or submit a pull request on the GitHub repository.

License

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