Skip to content

rogerramosme/js-pretty-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-pretty-logger 🎨

A Simple beaultiful to read console logger

Usage

First off all, you need to set the localStorage key showConsole. This was made to avoid some users of seeing these infos into console by default.

localStorage.setItem('showConsole', 'true');

Then just import and use:

// CommonJS
const logger = require('console-logger');
logger('AuthGuard', 'User login initialized', { type: 'info' });

//ES6
import logger from 'js-pretty-logger';
logger('AuthGuard', 'User login initialized', { type: 'info' });
11:53:08 AuthGuard • Initialized

Options

param type description
title string The context that will be logged. Just for visual.
message string The message that will be logged.. Just for visual too
options (optional) object object with log configurations
options.type string type of message that will be logged. Defines what is the title color. Options: default, danger, info, success or warn
options.isDetailed boolean Show the log time with detailed information. Good when you need to let yout application running from one day to another

Examples

All color options

logger('AuthGuard', 'User login initialized', { type: 'default' });
logger('AuthGuard', 'Searching for user...', { type: 'info' });
logger('AuthGuard', 'User not found!', { type: 'danger' });
logger('AuthGuard', 'User found!', { type: 'success' });
logger('AuthGuard', 'User password will expire soon', { type: 'warn' });

output

Detailed time

logger('AuthGuard', 'User password will expire soon', { isDetailed: true });

Output

Pro-tip 💡

Create methods inside yout code to abstract params:

// socket_middleware.js
import logger from 'js-pretty-logger';

// create a method to abstract title and type
const logIntoConsole = (message, type) => {
    logger('SocketMiddleware', message, {type: type});
}

// then use in yout code!
const onConnect = () => {
    logIntoConsole('Connected!', 'success');
}

const onError = () => {
    logIntoConsole('Failed to connect', 'danger');
}

About

A beaultiful to read console message

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published