0.1.0-alpha.3 • Published 5 years ago
@theshooter/tq-logger v0.1.0-alpha.3
@theshooter/tq-logger
Very simple console.log wrapper tailored for tanque's unique job...
Usage
DISCLAIMER: this package is at ALPHA dev stage. Some legacy
console.log
features may not be available yet
Installation
npm install @theshooter/tq-logger
Get started
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!');
Output:
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!');
Output:
Set SILENT MODE
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!');
Output:
Set Log Level
To set the log level, append a LEVEL string as second param:
const log = logger('Test Module');
log('Hello tq-logger!', 'warning');
Output:
Set Section
To set a log section, append a SECTION string as second param:
const log = logger('Test Module');
log('Hello tq-logger!', 'ìì++Test Section');
Output:
Set both Level & Section
const log = logger('Test Module');
log('Hello tq-logger!', 'warning', 'ìì++Test Section');
or even:
log('Hello tq-logger!', 'ìì++Test Section', 'warning');
Output:
Defaults
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' |