Socket
Socket
Sign inDemoInstall

glogg

Package Overview
Dependencies
1
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    glogg

Global logging utility


Version published
Weekly downloads
1.7M
increased by1%
Maintainers
2
Install size
12.4 kB
Created
Weekly downloads
 

Package description

What is glogg?

The glogg npm package is a logging utility designed to enable global logging. It allows developers to create a global logger that can be required and used across different modules in a Node.js application. This makes it easier to manage and configure logging in a centralized manner, especially in large-scale applications where consistent logging practices are crucial.

What are glogg's main functionalities?

Creating a global logger

This feature allows you to create a global logger instance that can be used throughout your application. You can name your logger (in this case, 'my-logger') and use various methods such as 'info', 'warn', 'error', etc., to log messages.

const logger = require('glogg')('my-logger');
logger.info('This is an info message');

Listening to log events

This feature enables you to listen to log events. You can attach event listeners to your logger for different log levels (e.g., 'info', 'warn', 'error') and define custom actions, such as logging to a file or sending notifications, when these events occur.

const logger = require('glogg')('my-logger');
logger.on('info', (msg) => {
  console.log(`Info: ${msg}`);
});
logger.info('This is an info message');

Other packages similar to glogg

Readme

Source

glogg

NPM version Downloads Build Status Coveralls Status

Global logging utility.

Usage

var getLogger = require('glogg');

var logger = getLogger('my-namespace');

// logs strings
logger.debug('The MOST verbose!');
logger.info('Some important info');
logger.warn('All the warnings to you');
logger.error('OH NO! SOMETHING HAPPENED!');

// supports util.format!
logger.info('%s style!', 'printf');

// log anything
logger.debug({ my: 'obj' });
logger.info([1, 2, 3]);

// somewhere else
logger.on('info', function (msg) {
  // do something with msg
});

// must be handled to avoid crashing process
logger.on('error', function (msg) {
  // now it won't crash
});

API

Note: This module makes no assumptions about the log levels and they will always be emitted. If you are looking to filter some out, your listeners will need to have extra logic.

getLogger([namespace])

Create a new logger at the given namespace (or the default if no namespace is provided). Returns an augmented sparkles EventEmitter object with 4 methods: debug(), info(), warn() and error(). When called, these methods emit an event with the same name. If the first argument is a string, the arguments are passed through node's util.format() before being emitted. Other parts of a node program can get the logger by namespace and listen for the events to be emitted.

logger.debug(msg, ...args)

Emits a debug event with the given msg.

If the first argument is a string, all arguments are passed to node's util.format() before being emitted.

If the first argument is not a string, all arguments will be emitted directly.

logger.info(msg, ...args)

Emits a info event with the given msg.

If the first argument is a string, all arguments are passed to node's util.format() before being emitted.

If the first argument is not a string, all arguments will be emitted directly.

logger.warn(msg, ...args)

Emits a warn event with the given msg.

If the first argument is a string, all arguments are passed to node's util.format() before being emitted.

If the first argument is not a string, all arguments will be emitted directly.

logger.error(msg, ...args)

Emits a error event with the given msg.

If the first argument is a string, all arguments are passed to node's util.format() before being emitted.

If the first argument is not a string, all arguments will be emitted directly.

Note: You must handle this event in some way or the node process will crash when an error event is emitted.

logger.on(event, fn)

Standard API from node's EventEmitter. Use this to listen for events from the logger methods.

License

MIT

Keywords

FAQs

Last updated on 23 Mar 2024

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