@strigi/logging

0.0.6 • Public • Published

🦉 Strigi Logging

Installation

npm add @strigi/logging

Root logger

The simplest way to use the library is to use directly the root logger.

import {get_logger} from '@strigi/logging';

const logger = get_logger();

logger.error('My error message');
logger.warn('My warn message');
logger.info('My info message');
logger.debug('My debug message');
logger.trace('My trace message');

Nested loggers

You can spawn children of the root logger, which by default inherit the root logger's configuration.

import {get_logger} from '@strigi/logging';

const root_logger = get_logger();
logger.info('Root logger info message');

const foo_logger = root_logger.get('foo')
logger.debug('Foo logger debug message');

const bar_logger = root_logger.get('bar')
logger.debug('Foo logger debug message');

const fizzbuzz_logger = root_logger.get('fizz.buzz')
logger.debug('Fizzbuzz logger debug message');

Using import.meta

// /home/strigi/project/foo.js
import {get_logger} from '@strigi/logging';

const log = get_logger(import.meta);
log.info('Hello'); // Category: 'root.home.strigi.project.foo'
// /home/strigi/project/src/foo/bar.js
import {get_logger} from '@strigi/logging';

const log = get_logger(import.meta, {base: 'src'});
log.info('Hello'); // Category: 'root.foo.bar'
// https://strigi.be/foo/bar/hello/world.js
import {get_logger} from '@strigi/logging';

const log = get_logger(import.meta, {base: 'foo'});
log.info('Hello'); // Category: 'root.bar.hello.world'

Configuration

Changing the root logger's category

import {get_logger} from '@strigi/logging';

// Also returns the root logger actually...
const root_logger = configure_logging({}, 'strigi');

// This is also the root logger
const logger = get_logger();
logger.info('Fizz'); // Category: 'strigi' instead of default 'root'

// Grandchild of the root logger
const bar = get_logger('foo.bar')
bar.info('Bar bar bar') // Category: 'strigi.foo.bar'

Readme

Keywords

Package Sidebar

Install

npm i @strigi/logging

Weekly Downloads

2

Version

0.0.6

License

LGPL-3.0

Unpacked Size

172 kB

Total Files

71

Last publish

Collaborators

  • strigi