NodeJS library for nice & easy console logs.
Install using yarn
or npm
.
$ yarn add yorker
$ npm install yorker --save
Import in one of your js
, ts
or vue
files and start using it.
import { yorker } from 'yorker';
const say = yorker.see('something');
say('something');
By default it will be switched off for production enviroment NODE_ENV="production"
.
Create a file in your project to have a singlethon instance of the logger. To instantiate the Yorker class you need two parameters to set up: Theme
and the flag enabled
.
import { Yorker, NYPDTheme } from 'yorker';
const theme = new NYPDTheme();
const enabled = process.env.NODE_ENV !== 'production';
export const newYorker = new Yorker(theme, enabled);
A new custom theme can be created by implementing the ITheme
interface.
It's very easy and has only one method see(msg)
that returns a function say(msg, error?)
.
const say = yorker.see('something');
say('everything is Okay');
say('there is an error', new Error('smth'));
function startMongo(config: { url: string }) {
const say = yorker.see(`Connecting to mongo: "${config.url}"`);
const client = new MongoClient(config.url, { raw: true, useNewUrlParser: true });
client.connect((err, client) => {
if (err) {
say('Error while connecting to mongo.', err);
return process.exit(1);
}
say('Connection to mongo succeeded.');
});
}