From da017609833be600da3289fb4dfbe40eb8731261 Mon Sep 17 00:00:00 2001 From: Eugene Terehov Date: Wed, 11 Nov 2020 23:38:23 +0200 Subject: [PATCH] Add tree shaking to feature set in README --- README.md | 2 ++ src/Logger.ts | 2 +- src/LoggerWithoutCallSite.ts | 12 ++++++++---- src/index.ts | 7 +++---- tests/error.test.ts | 12 ++++++++++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fba81044..5f861d5c 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ **Child logger with inheritance**
๐Ÿ™Š **Mask/hide secrets and keys**
๐Ÿ” **Native support for request IDs (`async_hooks`, `AsyncLocalStorage`)**
+๐ŸŒณ **Tree shaking support**
๐Ÿงฒ **Optionally catch all `console` logs**
โœ๏ธ **well documented**
@@ -84,6 +85,7 @@ log.fatal(new Error("I am a pretty Error with a stacktrace.")); * **Fully typed:** Written in TypeScript, fully typed, API checked with _api-extractor_, _TSDoc_ documented * **Source maps lookup:** Shows exact position also in TypeScript code (compile-to-JS), one click to IDE position * **Stack trace:** Callsites through native _V8 stack trace API_, excludes internal entries +* **Tree shake suport** via esm import syntax ([tree-shaking](https://webpack.js.org/guides/tree-shaking/)) * **Pretty Error:** Errors and stack traces printed in a structured way and fully accessible through _JSON_ (e.g. external Log services) * **Code frame:** `tslog` captures and displays the source code that lead to an error, making it easier to debug * **Object/JSON highlighting:** Nicely prints out an object using native Node.js `utils.inspect` method diff --git a/src/Logger.ts b/src/Logger.ts index 609c7924..0d12a298 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -15,4 +15,4 @@ export class Logger extends LoggerWithoutCallSite { super(settings, parentSettings); this._callSiteWrapper = wrapCallSite; } -} \ No newline at end of file +} diff --git a/src/LoggerWithoutCallSite.ts b/src/LoggerWithoutCallSite.ts index ad4f8f4a..a8927abe 100644 --- a/src/LoggerWithoutCallSite.ts +++ b/src/LoggerWithoutCallSite.ts @@ -1,4 +1,3 @@ - import { hostname } from "os"; import { normalize as fileNormalize } from "path"; import { inspect, format } from "util"; @@ -200,7 +199,10 @@ export class LoggerWithoutCallSite { const childSettings: ISettings = { ...this.settings, }; - const childLogger: Logger = new (this.constructor as any)(settings, childSettings); + const childLogger: Logger = new (this.constructor as any)( + settings, + childSettings + ); this._childLogger.push(childLogger); return childLogger; } @@ -360,7 +362,9 @@ export class LoggerWithoutCallSite { const relevantCallSites: NodeJS.CallSite[] = callSites.splice( this.settings.ignoreStackLevels ); - const stackFrame: NodeJS.CallSite = this._callSiteWrapper(relevantCallSites[0]); + const stackFrame: NodeJS.CallSite = this._callSiteWrapper( + relevantCallSites[0] + ); const stackFrameObject: IStackFrame = LoggerHelper.toStackFrameObject( stackFrame ); @@ -857,4 +861,4 @@ export class LoggerWithoutCallSite { ? formattedStr.replace(this._maskAnyRegExp, this.settings.maskPlaceholder) : formattedStr; } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 63730c26..5e1df478 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,8 +21,7 @@ export { TUtilsInspectColors, ISettings, ICodeFrame, -} from './interfaces'; - -export { Logger } from './Logger'; -export { LoggerWithoutCallSite } from './LoggerWithoutCallSite'; +} from "./interfaces"; +export { Logger } from "./Logger"; +export { LoggerWithoutCallSite } from "./LoggerWithoutCallSite"; diff --git a/tests/error.test.ts b/tests/error.test.ts index 5d0b08e2..5a1327ac 100644 --- a/tests/error.test.ts +++ b/tests/error.test.ts @@ -1,5 +1,10 @@ import "ts-jest"; -import { IErrorObject, ILogObject, Logger, LoggerWithoutCallSite } from "../src"; +import { + IErrorObject, + ILogObject, + Logger, + LoggerWithoutCallSite, +} from "../src"; import { doesLogContain } from "./helper"; let stdOut: string[] = []; @@ -20,7 +25,10 @@ const loggerConfig = { const loggerPretty: Logger = new Logger({ ...loggerConfig, type: "pretty" }); const loggerJson: Logger = new Logger({ ...loggerConfig, type: "json" }); -const loggerJsonWithoutCallsite: Logger = new LoggerWithoutCallSite({ ...loggerConfig, type: "json" }); +const loggerJsonWithoutCallsite: Logger = new LoggerWithoutCallSite({ + ...loggerConfig, + type: "json", +}); class TestError extends Error { constructor(message: string) {