Skip to content

loggerage-promisify is a helper for promisify methods of loggerage package

License

Notifications You must be signed in to change notification settings

lmfresneda/loggerage-promisify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loggerage-promisify

npm Loggerage version Love Travis Coveralls

Only work with loggerage verson >=2.0

loggerage-promisify is a helper for promisify methods of loggerage package

How to use

$ npm install --save loggerage-promisify

or

$ yarn add loggerage-promisify
const { Loggerage } = require("loggerage");
const promisify = require('loggerage-promisify')

const logger = promisify(new Loggerage("MY-APP"));

logger.debug("Hello world!") // is a promise now!
  .then(() => {
    return logger.getLog();
  })
  .then((log) => {
    // handle log!
  })
  .catch(handleError);

Or, if you want promisify only the actual async method, you can specify:

const { Loggerage } = require("loggerage");
const promisify = require('loggerage-promisify')

const logger = promisify(new Loggerage("MY-APP"), { onlyAsync: true });

logger.debug("Hello world!"); // is sync and NOT is a promise

logger.debugAsync("Hello again world!") // is async and promise!
  .then(() => {
    return logger.getLog();
  })
  .then((log) => {
    // handle log!
  })
  .catch(handleError);

Understanding

When you don't specify the onlyAsync property to true, the methods with 'Async' suffix are promisificated as you expect, like debugAsync, infoAsync, and synchronous methods like info, debug, getLog, etc. are matched to the previous asynchronous methods. For this reason it will be the same to call debug as to debugAsync, etc.

When you (yes) specify the onlyAsync property to true, only the methods with 'Async' suffix are promisificated, like debugAsync, infoAsync, etc.

Run test

$ npm install && npm test

or

$ yarn install && yarn run test

License

About

loggerage-promisify is a helper for promisify methods of loggerage package

Resources

License

Stars

Watchers

Forks

Packages

No packages published