JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q37878F
  • License Apache-2.0

Enhance Node.js console logging with clog-utils. Customize log presets, style messages, and reduce clutter.

Package Exports

  • clog-utils
  • clog-utils/lib/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (clog-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Clog Utils

This is a custom logging library that allows you to create and apply log presets, change log styles, and customize log messages in your Node.js applications while still using console.log.

Important Announcement

This module still in beta, please dont hesitate to Collaborate/Report issue!

Installation

You can install the library using npm:

npm install clog-utils

Getting Started

To get started, import the library and set it up:

// ES/Typescript
import { clogUtils } from 'clog-utils';
// or CJS
const { clogUtils } = require("clog-utils");

const logger = new clogUtils({ // example Presets
  warning: {
    prefix: '[Warning]',
    prefixcolor: 'red',
  },
  info: {
    prefix: '[Info]',
    prefixcolor: '#a8c9e3',
  }
});

Now, you can use console.log as usual, and it will apply your custom presets and styles:

console.log('This is a basic log message.');
console.log('This is an informational message.', 'info');
// or
console.log('This is an informational message.', { preset: "info" });
console.log('This is a warning message.', { preset: "Warning" });
// or you can set temp presets
console.log('This is a warning message.',  { preset: { prefix: 'Warning', prefixcolor: 'Red' }});
// you can use logger.log instead console.log if you want to.

Anti Spam feature

Clog Utils will begin tracking duplicate console messages, and you can experiment with this functionality using setInterval:

setInterval(() => {
 console.log('This is an counting message.', 'info'); // Output: [Info] This is an counting message. (number of duplicates)
}, 1000)

Usages

Restoring Original Logging

You can restore the original console logging behavior:

logger.restore();

you can use to retrive the console.log implamention.

logger.setup();

Managing Presets

You can manage presets using the following methods:

Applying Presets

Presets define log prefixes and styles. You can apply presets like this:

logger.addPreset({ info: { prefix: '[Info]', prefixcolor: 'green' }});
// you can use Hex color codes too!
console.log('This is an informational message.', 'info');

Set Presets

Set a collection of presets:

const presets = {
  info: { prefix: '[Info]', prefixcolor: 'green' },
  warning: { prefix: '[Warning]', prefixcolor: 'yellow' },
};

logger.setPresets(presets);

Remove Preset

Remove a preset by name:

logger.removePreset('info');

Get Preset

Get the configuration of a preset:

const infoPreset = logger.getPreset('info');
console.log(infoPreset); // { prefix: '[Info]', prefixcolor: 'green' }

Get All Presets

Get all presets as an array of objects:

const allPresets = logger.getAllPresets();
console.log(allPresets);
// [
//   { info: { prefix: '[Info]', prefixcolor: 'green' } },
//   { warning: { prefix: '[Warning]', prefixcolor: 'yellow' } },
//   { custom: { prefix: '[Custom]', prefixcolor: '\x1b[35m' } }
// ]

License

This library is licensed under the Apache 2.0 License. See the LICENSE file for details.