@holz/logger
TypeScript icon, indicating that this package has built-in type declarations

0.6.1 • Public • Published

@holz/logger

A lightweight and customizable logger for Node.js and browser environments.

Installation

Install with npm:

npm install @holz/logger

Usage

To use the logger, import it into your project:

import logger from '@holz/logger';

After that, you can start logging messages with different log levels:

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

By default, logs are formatted with a timestamp, log level, namespace (if provided), and message. You can also add a namespace to your logs to help organize them:

const dbLogger = logger.namespace('db');
dbLogger.info('Connected to database');

If you don't see logs, you may need to enable them. You can do this by setting the DEBUG environment variable to your-app* or setting localStorage.debug to your-app*. For example, to enable logs in a Node.js script:

DEBUG='your-app*' node script.js

Holz is suitable for use in other libraries as you can enable logs when needed, without cluttering downstream application logs.

Customizing the Logger

@holz/logger is a bundle of plugins that can be used separately to build a custom logger. The library uses several plugins, such as @holz/ansi-terminal-backend for colorizing logs, @holz/stream-backend for writing logs to files in plain text format, and @holz/console-backend for logging to the browser console.

Although the bundled logger is opinionated and not configurable, you can easily use the individual plugins to create a logger tailored to your needs. The logger's foundation is the createLogger(backend) function from @holz/core, and you can select the plugins to include based on your requirements.

For more details check out the documentation or look at an example.

Install

DownloadsWeekly Downloads

40

Version

0.6.1

License

MIT

Unpacked Size

6.83 kB

Total Files

9

Last publish

Collaborators

  • psychollama