@lowfat/log
v0.3.3
Published
A simple and easy-to-use logging tool, small enough to be included with client-side code, but works excellent with Node, and Deno, as well.
Downloads
666
Readme
Lowfat Log
A simple and easy-to-use logging tool, small enough to be included with client-side code, but works excellent with Node, and Deno, as well.
Usage
[!IMPORTANT]
@lowfat/logdoes currently not work in browsers (i.e., via UNPKG). Feel free to change that and let me know via a pull request!
Install the package with NPM, NodeJS is required:
npm i @lowfat/log
# or only for development purposes
npm i -D @lowfat/logDirectly import the package into your project:
import Log from '@lowfat/log';
Log.info('Works without initialization!');
// prints "[LFP] Works without initialization!"Customization
Change label
By default, every message is prefixed with [LFP], to change that, you have to initialize a new instance of the logger:
import Log from '@lowfat/log';
const sublabel = 'my sublabel';
const logger1 = new Log({ sublabel });
logger1.info('Now with custom label!');
// prints "[LFP/my sublabel] Now with custom label!"
const logger2 = new Log({ label: 'my label', sublabel });
logger2.warn('Custom label AND sublabel');
// prints "[my label/my sublabel] Custom label AND sublabel"Use this logger as your new default:
// ./logger.js
import Log from '@lowfat/log';
export const logger = new Log({ label: 'my label' });
// ./some-place-else.js
import { logger } from './path/to/logger.js';
logger.info('Works everywhere!');
// prints "[my label] Works everywhere!"Development
Clone this repository and install dependencies:
git clone https://codeberg.org/lowfatprophet/log.git
cd log
npm iStart a development watcher for faster iterations:
npm run devBuilding is done with tsdown:
npm run buildTesting is done with vitest:
npm run test