diff --git a/package-lock.json b/package-lock.json index ac3b5e4..47b996c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@hibas123/nodelogging", - "version": "1.5.0-alpha.2", + "name": "@hibas123/logging", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,12 +9,6 @@ "resolved": "https://registry.npmjs.org/@hibas123/utils/-/utils-2.0.2.tgz", "integrity": "sha512-5yrpuuUv0YlL2BixiTQLta4EmPLMNZ9Waorymu6dbERiSIcBxDs8mcJDUDW7CGiewpHHQUMsqLycLUYPDx0LWw==" }, - "@types/node": { - "version": "11.11.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.7.tgz", - "integrity": "sha512-bHbRcyD6XpXVLg42QYaQCjvDXaCFkvb3WbCIxSDmhGbJYVroxvYzekk9QGg1beeIawfvSLkdZpP0h7jxE4ihnA==", - "dev": true - }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -170,9 +164,9 @@ } }, "binary-extensions": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.0.tgz", - "integrity": "sha512-EgmjVLMn22z7eGGv3kcnHwSnJXmFHjISTY9E/S5lIcTD3Oxw05QTcBLNkJFzcb3cNueUdF/IN4U+d78V0zO8Hw==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz", + "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", "dev": true }, "boxen": { @@ -188,6 +182,14 @@ "string-width": "^2.0.0", "term-size": "^1.2.0", "widest-line": "^2.0.0" + }, + "dependencies": { + "camelcase": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "dev": true + } } }, "brace-expansion": { @@ -247,9 +249,9 @@ } }, "camelcase": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", - "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.0.tgz", + "integrity": "sha512-Y05ICatFYPAfykDIB7VdwSJ0LUl1yq/BwO2OpyGGLjiRe1fgzTwVypPiWnzkGFOVFHXrCXUNBl86bpjBhZWSJg==", "dev": true }, "capture-stack-trace": { @@ -267,6 +269,17 @@ "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } } }, "chokidar": { @@ -393,23 +406,6 @@ "supports-color": "^4.5.0", "tree-kill": "^1.1.0", "yargs": "^12.0.1" - }, - "dependencies": { - "has-flag": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", - "dev": true - }, - "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", - "dev": true, - "requires": { - "has-flag": "^2.0.0" - } - } } }, "configstore": { @@ -448,12 +444,14 @@ } }, "cross-spawn": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", - "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "dev": true, "requires": { - "lru-cache": "^4.0.1", + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" } @@ -586,13 +584,13 @@ "dev": true }, "execa": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", - "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", "dev": true, "requires": { - "cross-spawn": "^5.0.1", - "get-stream": "^3.0.0", + "cross-spawn": "^6.0.0", + "get-stream": "^4.0.0", "is-stream": "^1.1.0", "npm-run-path": "^2.0.0", "p-finally": "^1.0.0", @@ -1332,10 +1330,13 @@ "dev": true }, "get-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", - "dev": true + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "dev": true, + "requires": { + "pump": "^3.0.0" + } }, "get-value": { "version": "2.0.6", @@ -1390,6 +1391,14 @@ "timed-out": "^4.0.0", "unzip-response": "^2.0.1", "url-parse-lax": "^1.0.0" + }, + "dependencies": { + "get-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", + "dev": true + } } }, "graceful-fs": { @@ -1586,9 +1595,9 @@ "dev": true }, "is-glob": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.0.tgz", - "integrity": "sha1-lSHHaEXMJhCoUgPd8ICpWML/q8A=", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", "dev": true, "requires": { "is-extglob": "^2.1.1" @@ -1792,9 +1801,9 @@ } }, "mem": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.2.0.tgz", - "integrity": "sha512-5fJxa68urlY0Ir8ijatKa3eRz5lwXnRCTvo9+TbTGAuTFJOwpGcY0X05moBd0nW45965Njt4CDI2GFQoG8DvqA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", "dev": true, "requires": { "map-age-cleaner": "^0.1.1", @@ -1824,9 +1833,9 @@ } }, "mimic-fn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.0.0.tgz", - "integrity": "sha512-jbex9Yd/3lmICXwYT6gA/j2mNQGU48wCh/VzRd+/Y/PjYQtlg1gLMdZqvu9s/xH7qKvngxRObl56XZR609IMbA==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, "minimatch": { @@ -1872,9 +1881,9 @@ "dev": true }, "nan": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.1.tgz", - "integrity": "sha512-I6YB/YEuDeUZMmhscXKxGgZlFnhsn5y0hgOZBadkzfTRrZBtJDZeg6eQf7PYMIEclwmorTKK8GztsyOUSVBREA==", + "version": "2.13.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", + "integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==", "dev": true, "optional": true }, @@ -1919,6 +1928,17 @@ "touch": "^3.1.0", "undefsafe": "^2.0.2", "update-notifier": "^2.5.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } } }, "nopt": { @@ -2030,45 +2050,6 @@ "execa": "^1.0.0", "lcid": "^2.0.0", "mem": "^4.0.0" - }, - "dependencies": { - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - } - }, - "execa": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "dev": true, - "requires": { - "cross-spawn": "^6.0.0", - "get-stream": "^4.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - } } }, "p-defer": { @@ -2108,9 +2089,9 @@ } }, "p-try": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.1.0.tgz", - "integrity": "sha512-H2RyIJ7+A3rjkwKC2l5GGtU4H1vkxKCAGsWasNVd0Set+6i4znxbWy6/j16YDPJDWxhsgZiKAstMEP8wCdSpjA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, "package-json": { @@ -2377,9 +2358,9 @@ } }, "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "semver-diff": { @@ -2691,12 +2672,20 @@ "dev": true }, "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^2.0.0" + }, + "dependencies": { + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true + } } }, "term-size": { @@ -2706,6 +2695,40 @@ "dev": true, "requires": { "execa": "^0.7.0" + }, + "dependencies": { + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "execa": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", + "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", + "dev": true, + "requires": { + "cross-spawn": "^5.0.1", + "get-stream": "^3.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "get-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", + "dev": true + } } }, "timed-out": { @@ -3088,14 +3111,6 @@ "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" - }, - "dependencies": { - "camelcase": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.2.0.tgz", - "integrity": "sha512-IXFsBS2pC+X0j0N/GE7Dm7j3bsEBp+oTpb7F50dwEVX7rf3IgwO9XatnegTsDtniKCUtEJH4fSU6Asw7uoVLfQ==", - "dev": true - } } } } diff --git a/package.json b/package.json index 4988cff..3d14f9f 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { "name": "@hibas123/logging", - "version": "1.0.1", + "version": "1.1.0", "description": "", "main": "out/index.js", "types": "out/index.d.ts", "scripts": { "prepublish": "tsc", "build": "tsc", - "watch": "tsc --watch" + "watch-ts": "tsc --watch", + "watch-js": "nodemon out/test.js", + "watch": "concurrently npm:watch-*", + "test": "node out/test.js" }, "repository": { "type": "git", @@ -16,6 +19,8 @@ "author": "Fabian Stamm", "license": "MIT", "devDependencies": { + "concurrently": "^4.1.0", + "nodemon": "^1.18.10", "typescript": "^3.3.4000" }, "dependencies": { diff --git a/readme.md b/readme.md index 060a30c..721b2af 100644 --- a/readme.md +++ b/readme.md @@ -67,7 +67,6 @@ interface Message { }; date: Date; file: string; - customColors?:string; } enum LoggingTypes { diff --git a/src/base.ts b/src/base.ts index 4071d65..acb5342 100644 --- a/src/base.ts +++ b/src/base.ts @@ -112,17 +112,13 @@ export class LoggingBase { this.message(LoggingTypes.Warning, message); } - logWithCustomColors(type: LoggingTypes, colors: string, ...message: any[]) { - this.message(type, message, colors); - } - error(error: Error | string) { if (!error) error = "Empty ERROR was passed, so no informations available"; if (typeof error === "string") { let e = new Error() this.message(LoggingTypes.Error, [error, "\n", e.stack]); } else { - this.message(LoggingTypes.Error, [error.message, "\n", error.stack], undefined, getCallerFromExisting(error)); + this.message(LoggingTypes.Error, [error.message, "\n", error.stack], getCallerFromExisting(error)); } } @@ -130,7 +126,7 @@ export class LoggingBase { this.message(LoggingTypes.Error, message); } - private message(type: LoggingTypes, message: any[] | string, customColors?: string, caller?: { file: string, line: number }) { + private message(type: LoggingTypes, message: any[] | string, caller?: { file: string, line: number }) { let file_raw = caller || getCallerFile(); let file = `${file_raw.file}:${String(file_raw.line).padEnd(3, " ")}`; @@ -150,8 +146,25 @@ export class LoggingBase { let lines = mb.split("\n"); + let color = Colors.Reset; + switch (type) { + case LoggingTypes.Log: + //m += FgWhite + BgBlack; + break; + case LoggingTypes.Error: + color += Colors.FgRed;//FgWhite + BgRed + FgWhite; + break; + case LoggingTypes.Debug: + color += Colors.FgCyan; + break; + case LoggingTypes.Warning: + color += Colors.FgYellow; + break; + } + + let date = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, ''); - let prefix = `[ ${date} ][${LoggingTypes[type].toUpperCase().padEnd(5, " ")}][${file}]: `; + let prefix = `[${date}][${color}${LoggingTypes[type].toUpperCase().padEnd(5, " ")}${Colors.Reset}][${file}]: `; let formatted = lines.map(line => prefix + line); @@ -163,8 +176,7 @@ export class LoggingBase { raw: lines, formatted }, - type, - customColors + type } this.messageObservable.send(msg); diff --git a/src/consolewriter.ts b/src/consolewriter.ts index 13556e2..ccd6f4b 100644 --- a/src/consolewriter.ts +++ b/src/consolewriter.ts @@ -11,29 +11,9 @@ export class ConsoleWriter implements Adapter { 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)) + lines.forEach(line => console.log(name + line + Colors.Reset)) } } \ No newline at end of file diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..717a573 --- /dev/null +++ b/src/test.ts @@ -0,0 +1,30 @@ +import { Logging, LoggingBase } from "."; + +Logging.log("test") +Logging.log("i", "am", { a: "an" }, 1000); +Logging.error(new Error("fehler 001")); +Logging.debug("Some Debug infos"); +Logging.errorMessage("i", "am", "an", "error"); + +Logging.log("\x1b[31m\x1b[31m\x1b[31m\x1b[31m\x1b[31m\x1b[31m TEST \x1b[31m\x1b[31m\x1b[31m") + +let err = new Error() +if (typeof err.stack !== "string") console.log("Stacktrace invalid", err.stack) + +let cus = new LoggingBase({ name: "test" }); +cus.log("Hello from custom Logger") + +let cus2 = new LoggingBase("test2"); +cus2.log("Hello from custom Logger 2") + +let cus22 = new LoggingBase("test2"); +cus22.log("Hello from custom Logger 22") +cus2.log("Hello from custom Logger 2") +cus22.log("Hello from custom Logger 22") +cus2.log("Hello from custom Logger 2") +cus22.log("Hello from custom Logger 22") +cus2.log("Hello from custom Logger 2") +cus22.log("Hello from custom Logger 22") +cus2.log("Hello from custom Logger 2") +cus22.log("Hello from custom Logger 22") +cus2.log("Hello from custom Logger 2") \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index d285d21..9808947 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,7 +16,6 @@ export interface Message { }; date: Date; file: string; - customColors?: string; } export interface Adapter {