Giter Site home page Giter Site logo

leucine's Introduction

Screenshot 2023-01-29 at 2 55 53 PM

⚛️ leucine

A tiny, hybrid logging framework for client and server side applications.

  • ✅ formatted, easy-to-read logs
  • ✅ automatic distinction between server-side and client-side logging
  • ✅ emoji first logging indicators
  • ✅ comes with 4 logging states (debug, info, warn, error)
  • ✅ easily configurable

Getting started

First, install leucine using npm/yarn/pnpn:

## npm
npm i leucine --save-dev

## yarn
yarn add leucine -D

## pnpm
pnpm add leucine -D

Then, import any of the logging modes as named imports:

import { debug, info, warn, error } from "leucine"

🎉 You're now ready to start logging:

const sum = (a, b) => a + b;

debug(sum(1,2)); //🐛 [01/01/2023 12:00:00] (debug) in index.ts: 3

Leucine formats logs in both the server side and client side environment, giving you a roundabout logging experience.

📘 Documentation

Configuring leucine

Leucine ships with a sensible, default configuration. Nonetheless, if you'd like to tinker with the defaults then you can do so in two ways:

  1. Import the named configure function
  2. Import the Leucine class and instantiate a new class with your configuration.

Both methods are viable, pick the one you're most comfortable with (using a function vs. using a class).

Then, pass in your configuration. Below we represent the available keys you can use to configure leucine:

import {configure} from "leucine" // function-based
import Leucine from "leucine" // class-based

configure({
    debugColor?: Colors;
	infoColor?: Colors;
	warnColor?: Colors;
	errorColor?: Colors;
	displayDate?: boolean;
	dateFormat?: DateFormat;
	displayTime?: boolean;
	showMilliseconds?: boolean;
	displayArgTypes?: boolean;  
})

const logger = new Leucine({
    debugColor?: Colors;
	infoColor?: Colors;
	warnColor?: Colors;
	errorColor?: Colors;
	displayDate?: boolean;
	dateFormat?: DateFormat;
	displayTime?: boolean;
	showMilliseconds?: boolean;
	displayArgTypes?: boolean;
})

To configure colors, import the Colors enum from leucine and use it when overriding the default colors:

import {Colors} from "leucine"

const configuration = {
    debugColor: Color.Red;
    //...
}

To configure date formatting, import the DateFormat enum from leucine and use it to override the default date formating:

import {DateFormat} from "leucine"
const configuration = {
    dateFormat: DateFormat.YEAR_MONTH_DAY   
    //...
}

Passing variable args to log

To pass a variable amount of arguments to log to the console or to log multiple things, use an array like so:

import {debug} from "leucine"

const someVar = "I'm a variable!"

debug(["This is a string", someVar, 10]) // 🐛 (debug): ["This is a string", "I'm a variable", 10]

⚙️ API Reference

Leucine(config)

  • config: LeucineConfig
  • Returns instantiated Leucine class

debug(arg)

  • arg: T
  • Returns void

info(arg)

  • arg: T
  • Returns void

warn(arg)

  • arg: T
  • Returns void

error(arg)

  • arg: T
  • Returns void

configure(config)

  • config: LeucineConfig
  • Returns void

leucine's People

Contributors

shaunchander avatar therealemissions avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.