loggerify

2.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i loggerify

Weekly Downloads

1

Version

2.0.1

License

ISC

Unpacked Size

14 kB

Total Files

16

Last publish

Collaborators

  • danielsinaimain