Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

danielsinai/loggerify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loggerify

Fast, lightweight, minimalist logging framework for node.

Installation

$ npm install loggerify

Quick Start

const config = {
    error: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.error
    },
    start: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.info
    },
    end: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.debug
    },
}
const loggerifyMe = () => console.log('LOG ME NOW')
const loggerify = require('loggerify')
const loggerifiedFunction = loggerify(config)(loggerifyMe)

loggerifiedFunction()
// function loggerifyMe started with the arguments: {}
// LOG ME NOW
// function loggerifyMe ended successfully

Features

  • Logging as config
  • Easy to use
  • Wrapping Classes, objects, Functions and Arrow Functions at the same api

Motivation

Logging can become preety tough and uncomftorable, while you add more and more functions the code becoming less readable and clean. instead of doing logger.info evrey second line of code, you can use a loggerify framework that will do that for you!

Examples

const config = {
    error: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.error
    },
    start: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.info
    },
    end: {
        shouldLog: true,
        exceptions: [],
        logFunction: console.debug
    },
}
const loggerify = require('loggerify')
const configuredLoggerifier = loggerify(config)

Loggerify Class

class Dog {
   constructor() {
   }

   bark() {
       console.log('WOOF')
   }
}

const loggeredDog = new (configuredLoggerifier(Dog));

loggeredDog.bark();

//function bark started with the arguments: {}
//WOOF
//function bark ended successfully

Loggerify Object

const dog =  {
   bark: () => {
       console.log('WOOF')
   }
}

const loggeredDog =  configuredLoggerifier(dog);

loggeredDog.bark();
//function bark started with the arguments: {}
//WOOF
//function bark ended successfully

Loggerify Function

function bark () {
   console.log('WOOF');
}

const loggeredBark =  configuredLoggerifier(bark);

loggeredBark();
//function bark started with the arguments: {}
//WOOF
//function bark ended successfully

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

What's next?

  • Custom log message by using function name as key
  • Injecting custom log function to the function as parameter

Contributing

Feel free to open issues and to share PR's :)

People

The original author of Loggerify is Daniel Sinai

License

MIT

About

NPM lib for logging your applicaion as config

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published