new LoggerBuilder()
- Source:
Pretty CLI Logger, with possibility to replace default nodejs' console logger
Examples
// =============================
// Use Logger as 💻 instance
// =============================
const { LoggerBuilder } = require('@sgapps.io/server');
const logger = new LoggerBuilder();
logger.log("Hello world");
// replace default console
const { LoggerBuilder } = require('@sgapps.io/server');
const logger = new LoggerBuilder();
logger.decorateGlobalLogger();
console.log("Console Messages are decorated now");
Members
_debug :boolean
- Source:
Type:
- boolean
_format :string
- Source:
this parameter may be changed if you decide to change decoration schema
Type:
- string
Example
// Insert an message in VT100 format
logger._format = "\x1b[7m {{timestamp}} [{{TYPE}}] <{{title}}> {{file}}:{{line}} ({{method}}){{stack}}\x1b[7m";
_headerFormatters :Array.<headerFormatter>
- Source:
Type:
- Array.<headerFormatter>
Methods
decorateGlobalLogger()
- Source:
error(…messages)
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messages |
any |
<repeatable> |
info(…messages)
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messages |
any |
<repeatable> |
log(…messages)
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messages |
any |
<repeatable> |
prettyCli(ref, indentopt, separatoropt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ref |
any | |||
indent |
number |
<optional> |
||
separator |
string |
<optional> |
" "
|
prompt(callback, message)
- Source:
Example
logger.prompt("rerun tests? [y/n]: ", function (err, buffer) {
// trim spaces from response
var response = buffer.toString().replace(/^\s*(.*?)\s*$/, '$1');
if (response === 'y') {
// write your code
}
});
Parameters:
Name | Type | Description |
---|---|---|
callback |
LoggerBuilderPrompt | |
message |
string | Buffer |
warn(…messages)
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messages |
any |
<repeatable> |
Type Definitions
headerFormatter(info)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
info |
headerFormatterInfo |
headerFormatterInfo
- Source:
Properties:
Name | Type | Description |
---|---|---|
time |
string | |
type |
string | |
file |
string | |
line |
string | |
method |
string | |
path |
string | |
stack |
string |
Type:
- object