39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
|
import { ObservableInterface } from "@hibas123/utils";
|
||
|
import { Colors } from "./index";
|
||
|
import { Adapter, LoggingTypes, Message } from "./types";
|
||
|
|
||
|
|
||
|
export class ConsoleWriter implements Adapter {
|
||
|
init(observable: ObservableInterface<Message>) {
|
||
|
observable.subscribe(this.onMessage.bind(this));
|
||
|
}
|
||
|
|
||
|
flush() { }
|
||
|
|
||
|
onMessage(message: Message) {
|
||
|
let consoleLogFormat = Colors.Reset;
|
||
|
if (!message.customColors) {
|
||
|
switch (message.type) {
|
||
|
case LoggingTypes.Log:
|
||
|
//m += FgWhite + BgBlack;
|
||
|
break;
|
||
|
case LoggingTypes.Error:
|
||
|
consoleLogFormat += Colors.FgRed;//FgWhite + BgRed + FgWhite;
|
||
|
break;
|
||
|
case LoggingTypes.Debug:
|
||
|
consoleLogFormat += Colors.FgCyan;
|
||
|
break;
|
||
|
case LoggingTypes.Warning:
|
||
|
consoleLogFormat += Colors.FgYellow;
|
||
|
break;
|
||
|
}
|
||
|
} else {
|
||
|
consoleLogFormat += message.customColors;
|
||
|
}
|
||
|
|
||
|
let lines = message.text.formatted;
|
||
|
let name = "";
|
||
|
if (message.name) name = `[${message.name}]=>`;
|
||
|
lines.forEach(line => console.log(consoleLogFormat + name + line + Colors.Reset))
|
||
|
}
|
||
|
}
|