ConsLog
The console, rewritten from scratch.
Usage
To install,
npm install conslog
or
yarn add conslog
After that, there are three ways to use ConsLog. The first way is to replace the console
object.
delete console;
const console = require('conslog');
The second, semi-safe way is to move the console
object.
const v8 = require('v8');
const clone = obj => {
return v8.deserialize(v8.serialize(obj));
};
const oldConsole = clone(console)
delete console;
const console = require('conslog')
The third, safer way, is to include it as a separate package.
const cons = require('conslog');
Functions
console
is ConsLog, oldC
is the original console
.
log
function log(msg: any, ...optionalParams?: any[]);
Logs to stdout
. Works exactly like oldC.log
except for the indentation.
warn
function warn(msg: any, head?: string, ...optionalParams?: any[]);
Logs to stdout
as a warning. Prefixed with 'warn' or head
.
info
function info(msg: any, head?: string, ...optionalParams?: any[]);
Logs to stdout
as an information. Prefixed with 'info' or head
.
error
function error(e: Error, head?: string, ...optionalParams?: any[]);
Logs to stdout
as an error. Doesn't throw. Prefixed with 'err' or head
.
success
function success(msg: any, head?: string, ...optionalParams?: any[]);
Logs to stdout
as a success message. Prefixed with 'succ' or head
.
fatal
function fatal(e: Error, head?: string, ...optionalParams?: any[]);
Logs to stdout
as a fatal error. Throws. Prefixed with 'fatal' or head
.
changeTheme
interface Theme {
i: string[],
hi: string[],
w: string[],
hw: string[],
e: string[],
he: string[],
f: string[],
hf: string[],
s: string[],
hs: string[],
c: string[],
hc: string[],
g: string[]
}
function changeTheme(theme: Theme);
Sets the color theme. See the colors
doc for information on how to write a theme.
Variables
indentationSteps
let indentationSteps: number = 1;
How many spaces to indent each time.
maxIndent
let maxIndent: number = 10;
The maximum indentation you can reach. Set to -1 for no limit.
msg
interface Messages {
info: string,
warn: string,
error: string,
fatal: string,
catched: string,
success: string,
groupIn: string,
groupOut: string
}
let msg: Messages = {
info: " INFO ",
warn: " WARN ",
error: " ERR ",
fatal: "FATAL ",
catched: "CATCH ",
success: " SUCC ",
groupIn: "> ",
groupOut: "< "
}
The prefixes applied to the specific logging functions.
License
MIT