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
indent_style = space
indent_size = 3

2
package-lock.json generated
View File

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

View File

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

View File

@ -1,6 +1,12 @@
import { ObservableInterface } from "@hibas123/utils";
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";
@ -128,20 +134,21 @@ export class ConsoleAdapter implements Adapter {
if (message.name) prefix = `[${message.name}]=>`;
if (browser) {
let formats: string[] = [];
let text = lines.map(line => {
let text = lines
.map(line => {
let [t, fmts] = this.formatLine(line);
formats.push(...fmts);
return t;
}).join("\n");
return prefix + t;
})
.join("\n");
// console.log(formats);
console.log(text, ...formats);
} else {
lines.forEach(line => {
let [text] = this.formatLine(line);
console.log(prefix + text);
})
});
}
}
}