Also adding prefix to browser console output

This commit is contained in:
Fabian Stamm 2020-03-21 21:13:46 +01:00
parent 675ec50139
commit ce9742a20e
4 changed files with 145 additions and 137 deletions

View File

@ -1,3 +1,4 @@
[*]
charset = utf-8 charset = utf-8
indent_style = space indent_style = space
indent_size = 3 indent_size = 3

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/logging", "name": "@hibas123/logging",
"version": "2.1.4", "version": "2.1.5",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/logging", "name": "@hibas123/logging",
"version": "2.1.4", "version": "2.1.5",
"description": "", "description": "",
"main": "out/index.js", "main": "out/index.js",
"types": "out/index.d.ts", "types": "out/index.d.ts",

View File

@ -1,6 +1,12 @@
import { ObservableInterface } from "@hibas123/utils"; import { ObservableInterface } from "@hibas123/utils";
import { Colors } from "./index"; import { Colors } from "./index";
import { Adapter, Message, FormattedLine, TerminalFormats, FormatTypes } from "./types"; import {
Adapter,
Message,
FormattedLine,
TerminalFormats,
FormatTypes
} from "./types";
const browser = typeof window !== "undefined"; const browser = typeof window !== "undefined";
@ -9,7 +15,7 @@ export class ConsoleAdapter implements Adapter {
observable.subscribe(this.onMessage.bind(this)); observable.subscribe(this.onMessage.bind(this));
} }
flush() { } flush() {}
// TODO: Check if required! // TODO: Check if required!
// private escape(text: string): string { // private escape(text: string): string {
@ -128,20 +134,21 @@ export class ConsoleAdapter implements Adapter {
if (message.name) prefix = `[${message.name}]=>`; if (message.name) prefix = `[${message.name}]=>`;
if (browser) { if (browser) {
let formats: string[] = []; let formats: string[] = [];
let text = lines.map(line => { let text = lines
.map(line => {
let [t, fmts] = this.formatLine(line); let [t, fmts] = this.formatLine(line);
formats.push(...fmts); formats.push(...fmts);
return t; return prefix + t;
}).join("\n"); })
.join("\n");
// console.log(formats); // console.log(formats);
console.log(text, ...formats); console.log(text, ...formats);
} else { } else {
lines.forEach(line => { lines.forEach(line => {
let [text] = this.formatLine(line); let [text] = this.formatLine(line);
console.log(prefix + text); console.log(prefix + text);
}) });
} }
} }
} }