Package Exports
- euberlog
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (euberlog) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
euberlog
A beautiful nodejs logger.
Install
To install euberlog, run:
$ npm install euberlogUsage
Simple
const { Logger } = require('euberlog');
const logger = new Logger();
logger.info('Informazione');
logger.success('Successo!!!');
logger.debug('Debug');
logger.warning('Warning!!');
logger.error('Errore');
logger.info('My car is:', { constructor: 'Toyota', model: 'Yaris', year: 2004 });
Br and hr
const { Logger } = require('euberlog');
const logger = new Logger();
// Prints one line of '-'
logger.hr();
// Prints two empty lines
logger.br(2);
logger.info('My name is Eugenio');
// Prints two empty lines
logger.br(2);
// Prints five lines of red '*'
logger.hr(5, 'red', '*');
With scope
const { Logger } = require('euberlog');
const logger = new Logger('MAIN');
// Adds {MAIN} before the message
logger.info('Informazione');
logger.success('Successo!!!');
logger.error('The error is:', new Error('Errore'));
With options
const { Logger } = require('euberlog');
const logger = new Logger({
scope: 'MYSCOPE',
debug: false, // Hides the debug logs
palette: { // Overrides the default colour palette
primary: {
info: 'orange',
success: '(146,133,255)'
},
secondary: {
info: '#ffd485',
success: 'blue'
}
}
});
logger.info('Informazione');
logger.success('Successo!!!');
logger.debug('This is not shown');
API
Logger
The logger class, its instances will be the euber loggers.
Syntax:
const logger = new Logger(options);
Options:
The options parameter is a string or a Options object. If it is a string, it like passing an Options object with only the property scope with that string as value.
Options parameters:
- scope: Optional. A
stringrepresenting the scope of the logger. It is prepended between{}before each message. If it isnullthe scope will not be printed. - debug: Optional. If
true, the debug messages will be printed. - palette: Optional. An
objectof typePaletterepresenting the colours used by the logger.
Palette parameters:
- primary: Optional. An
objectofPaletteDefinitionstype that defines the colours for the primary part of a message, namely the[TAG]and an eventual{SCOPE}. - secondary: Optional. An
objectofPaletteDefinitionstype that defines the colours for the secondary part of a message, namely the message passed to the logger function.
PaletteDefinitions:
- info: The colour for the info logs. Note: the colour can be a valid
chalkcolour (such as'white'), an hex colour (such as'#FFFFFF'), an RGB colour (such as'(255,255,255)') or a css keyword (such as'orange') - success: The colour for the success logs. Note: the colour can be a valid
chalkcolour (such as'white'), an hex colour (such as'#FFFFFF'), an RGB colour (such as'(255,255,255)') or a css keyword (such as'orange') - debug: The colour for the debug logs. Note: the colour can be a valid
chalkcolour (such as'white'), an hex colour (such as'#FFFFFF'), an RGB colour (such as'(255,255,255)') or a css keyword (such as'orange') - warning: The colour for the warning logs. Note: the colour can be a valid
chalkcolour (such as'white'), an hex colour (such as'#FFFFFF'), an RGB colour (such as'(255,255,255)') or a css keyword (such as'orange') - error: The colour for the error logs. Note: the colour can be a valid
chalkcolour (such as'white'), an hex colour (such as'#FFFFFF'), an RGB colour (such as'(255,255,255)') or a css keyword (such as'orange')
Note: the default_options are:
const DEFAULT_OPTIONS = {
palette: {
primary: {
info: 'blue',
success: 'green',
debug: 'gray',
warning: 'yellow',
error: 'red'
},
secondary: {
info: '#81A2BE',
success: '#B5BD68',
debug: '#C5C8C6',
warning: '#F0C674',
error: '#CC6666'
}
},
debug: true,
scope: null
};Methods:
- info(message: string, object?: any): void: Logs an info message. The format is
[INFO] |{SCOPE}| message |object|, where|word|is optional. - success(message: string, object?: any): void: Logs an success message. The format is
[SUCCESS] |{SCOPE}| message |object|, where|word|is optional. - debug(message: string, object?: any): void: Logs an debug message. The format is
[DEBUG] |{SCOPE}| message |object|, where|word|is optional. - warning(message: string, object?: any): void: Logs an warning message. The format is
[WARNING] |{SCOPE}| message |object|, where|word|is optional. - error(message: string, object?: any): void: Logs an error message. The format is
[ERROR] |{SCOPE}| message |object|, where|word|is optional. - br(n?: number): void: Logs
nempty lines. The default value ofnis1. - hr(n?: number, color?: string, symbol: string): void: Logs
nhr lines, coloured withcolorand constituted bysymbolcharacters. THe default value ofnis1, the default colour is'white'and the default symbol is'-'. - setOptions(options?: Options | string): void: It changes the options of the logger instance. It is almost as using the class constructor, with the difference that a new instance will not be created.
Build
To build the module make sure you have the dev dependencies installed.
The project is written in Typescript, bundled with Webpack and linted with ESLint.
Lint
In order to lint the source code:
$ npm run lintIn order to lint and fix the source code:
$ npm run lint:fixTranspile
$ npm run transpileThe source folder will be compiled in the dist folder. Also the type declarations will be generated.
Bundle
$ npm run bundleThe source folder will be compiled in the bundled folder. It will contain the bundled index.js and index.d.ts files.