Cleaned up logger
This commit is contained in:
parent
50e9583e0f
commit
bd145abcb7
@ -1,8 +1,8 @@
|
|||||||
import * as pino from "pino";
|
import * as pino from "pino";
|
||||||
|
|
||||||
type Level = "default" | 60 | 50 | 40 | 30 | 20 | 10;
|
type Level = "default" | "60" | "50" | "40" | "30" | "20" | "10";
|
||||||
|
|
||||||
const levels = {
|
const levels: {[level in Level]: string } = {
|
||||||
default: "USERLVL",
|
default: "USERLVL",
|
||||||
60: "FATAL",
|
60: "FATAL",
|
||||||
50: "ERROR",
|
50: "ERROR",
|
||||||
@ -12,7 +12,7 @@ const levels = {
|
|||||||
10: "TRACE",
|
10: "TRACE",
|
||||||
};
|
};
|
||||||
|
|
||||||
const levelColors = {
|
const levelColors: {[level in Level]: string } = {
|
||||||
default: "text-decoration: underline; color: #000000;",
|
default: "text-decoration: underline; color: #000000;",
|
||||||
60: "text-decoration: underline; background-color: #FF0000;",
|
60: "text-decoration: underline; background-color: #FF0000;",
|
||||||
50: "text-decoration: underline; color: #FF0000;",
|
50: "text-decoration: underline; color: #FF0000;",
|
||||||
@ -40,7 +40,7 @@ function concatColored(...coloredStrings: ColoredString[]): ColoredString {
|
|||||||
|
|
||||||
const standardKeys = ["pid", "hostname", "name", "level", "time", "v", "source", "msg"];
|
const standardKeys = ["pid", "hostname", "name", "level", "time", "v", "source", "msg"];
|
||||||
|
|
||||||
function formatter(value: any) {
|
function write(value: any) {
|
||||||
let line = concatColored(
|
let line = concatColored(
|
||||||
// makeColored(formatTime(value, " ")),
|
// makeColored(formatTime(value, " ")),
|
||||||
formatSource(value),
|
formatSource(value),
|
||||||
@ -53,12 +53,10 @@ function formatter(value: any) {
|
|||||||
str: "%c" + value.msg, args: ["color: #00FFFF"],
|
str: "%c" + value.msg, args: ["color: #00FFFF"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let args = [line.str].concat(line.args);
|
const args = [line.str].concat(line.args)
|
||||||
if (value.type === "Error") {
|
.concat([
|
||||||
args = args.concat([value.stack]);
|
(value.type === "Error") ? value.stack : filter(value),
|
||||||
} else {
|
]);
|
||||||
args = args.concat([filter(value)]);
|
|
||||||
}
|
|
||||||
let fn;
|
let fn;
|
||||||
if (value.level >= 50) {
|
if (value.level >= 50) {
|
||||||
fn = console.error;
|
fn = console.error;
|
||||||
@ -118,7 +116,7 @@ function formatSource(value: any): { str: string, args: any[] } {
|
|||||||
|
|
||||||
function formatLevel(value: any): ColoredString {
|
function formatLevel(value: any): ColoredString {
|
||||||
const level = value.level as Level;
|
const level = value.level as Level;
|
||||||
if (levelColors.hasOwnProperty(level as string)) {
|
if (levelColors.hasOwnProperty(level)) {
|
||||||
return {
|
return {
|
||||||
str: "%c" + levels[level] + "%c",
|
str: "%c" + levels[level] + "%c",
|
||||||
args: [levelColors[level], ""],
|
args: [levelColors[level], ""],
|
||||||
@ -132,7 +130,7 @@ function formatLevel(value: any): ColoredString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let logger: pino.Logger = pino({
|
let logger: pino.Logger = pino({
|
||||||
browser: { write: formatter },
|
browser: { write },
|
||||||
level: "trace",
|
level: "trace",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user