Skip to content
/ logger Public

Zero dependency, light-weight, blazing fast customizable logging library

License

Notifications You must be signed in to change notification settings

v3xlabs/logger

Repository files navigation

lvksh logger

MINIFIED SIZE COVERAGE LANGUAGES DEPENDENCIRES NPM

Zero dependency, lightweight, blazingly fast customizable logging library

Table of Contents

Installation

Using npm:

npm install @lvksh/logger

or if you prefer to use the yarn package manager:

yarn add @lvksh/logger

Usage

Get started by creating your logger

import { createLogger } from '@lvksh/logger';
import chalk from 'chalk';

const log = createLogger(
    {
        ok: {
            label: chalk.greenBright`[OK]`,
            newLine: '| ',
            newLineEnd: '\\-',
        },
        debug: chalk.magentaBright`[DEBUG]`,
        info: {
            label: chalk.cyan`[INFO]`,
            newLine: chalk.cyan`⮡`,
            newLineEnd: chalk.cyan`⮡`,
        },
        veryBigNetworkError: chalk.bgRed.white.bold`[NETWORK]`,
    },
    { padding: 'PREPEND' },
    console.log
);

And now log to your hearts content

log.ok('This is the best logging', 'library', 'you');
log.info('will probably');
log.debug('ever use');
log.veryBigNetworkError`Never Gonna Give You Up!`;
log.debug('in', 'your', 'life', "you're", 'welcome');
log.info('item 1', 'item 2', 'item 3', 'item 4', 'item 5');

Which produces the following result

Other Themes:

LoggerConfig

This section is still work in progress.

MethodConfig

This section is still work in progress.

Shimming console.log

Do you still type console.log out of habit? Not a problem, simply run shimLog with your logger, and your log function of choice and voila. Now every stray console.log will be on steroids from now on!

import { createLogger, shimLog } from '@lvksh/logger';
import chalk from 'chalk';

const log = createLogger({
    debug: chalk.magentaBright`[DEBUG]`,
});

// Replaces `console.log` with `log.debug` !
shimLog(log, 'debug');

File Logging

import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger } from '@lvksh/logger/lib/file-log';

const log = createLogger(
    {
        OK: 'OK',
        INFO: 'INFO',
    },
    { divider: ' | ' },
    FileLogger({
        mode: 'NEW_FILE',
        path: join(__dirname, 'logs'),
        namePattern: 'test.txt',
    })
);

log.OK('Hello World');

Multi Logging

import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger, FileLoggerConfig } from '@lvksh/logger/lib/file-log';

const fileConfig: FileLoggerConfig = {
    mode: 'NEW_FILE',
    path: join(__dirname, '../logs'),
    namePattern: 'test.txt'
}
const methodConfig = {
    OK: 'OK',
    INFO: 'INFO'
}

const log = createLogger(
    methodConfig,
    { divider: ' | ' },
    [FileLogger(fileConfig), console.log]
);

export default log;

log.OK('Hello World');

Contributors

LICENSE

This package is licensed under the GNU Lesser General Public License.

Regex matching within this package is sourced from ansi-regex, which is licensed under the MIT license.