Code Monkey home page Code Monkey logo

logger's Introduction

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.

logger's People

Contributors

lucemans avatar thejoshuahendrix avatar svemat01 avatar antony1060 avatar prokopschield avatar tg-techie avatar loidnoir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.