Very simple console.log wrapper tailored for tanque's unique job...
DISCLAIMER: this package is at ALPHA dev stage. Some legacy
console.log
features may not be available yet
npm install @theshooter/tq-logger
Importing tq-logger
returns a function to initialize the logger with your local settings
import logger from '@theshooter/tq-logger'
Just create a wrapper calling tq-logger
passing a string argument to set the local module name:
const log = logger('Test Module');
log('Hello tq-logger!');
Or an optional object to override default settings:
const log = logger('Test Module',{
styles: {
heading: {
INFO: "background-color: blue; color: white;",
},
text: {
INFO: "color: blue;",
}
}
});
log('Hello tq-logger!');
To disable logging and use SILENT MODE (i.e. in production) set the custom
settings object property mode
to 'silent'
:
const log = logger('Test Module',{
mode: 'silent'
});
log('Hello tq-logger!');
To set the log level, append a LEVEL string as second param:
const log = logger('Test Module');
log('Hello tq-logger!', 'warning');
To set a log section, append a SECTION string as second param:
const log = logger('Test Module');
log('Hello tq-logger!', 'ìì++Test Section');
const log = logger('Test Module');
log('Hello tq-logger!', 'warning', 'ìì++Test Section');
or even:
log('Hello tq-logger!', 'ìì++Test Section', 'warning');
Default options object:
const OPTIONS = {
mode: "debug",
styles: {
heading: {
ERROR: "background-color: red; color: yellow;",
WARNING: "background-color: yellow; color: red;",
INFO: "background-color: green; color: white;",
DEBUG: "background-color: blue; color: white;"
},
section: "font-style: italic",
text: {
ERROR: "color: red;",
WARNING: "color: orange;",
INFO: "color: green;",
DEBUG: "color: blue;"
}
}
};
Log Levels IDENTIFIERS:
level | IDENTIFIER | identifier |
---|---|---|
error | 'ERROR' | 'error' |
warning | 'WARNING' | 'warning' |
info | 'INFO' | 'info' |
debug | 'DEBUG' | 'debug' |
default | 'INFO' |