Skip to content

Commit da01760

Browse files
committed
Add tree shaking to feature set in README
1 parent a97d463 commit da01760

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
👨‍👧‍👦 **Child logger with inheritance**<br>
2828
🙊 **Mask/hide secrets and keys**<br>
2929
🔍 **Native support for request IDs (<a href="https://nodejs.org/api/async_hooks.html#async_hooks_async_hooks" target="_blank">`async_hooks`</a>, <a href="https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage" target="_blank">`AsyncLocalStorage`</a>)**<br>
30+
🌳 **Tree shaking support**<br>
3031
🧲 **Optionally catch all `console` logs**<br>
3132
✍️ **well documented**<br>
3233

@@ -84,6 +85,7 @@ log.fatal(new Error("I am a pretty Error with a stacktrace."));
8485
* **Fully typed:** Written in TypeScript, fully typed, API checked with <a href="https://api-extractor.com" target="_blank">_api-extractor_</a>, <a href="https://github.com/microsoft/tsdoc" target="_blank">_TSDoc_</a> documented
8586
* **Source maps lookup:** Shows exact position also in TypeScript code (compile-to-JS), one click to IDE position
8687
* **Stack trace:** Callsites through native <a href="https://v8.dev/docs/stack-trace-api" target="_blank">_V8 stack trace API_</a>, excludes internal entries
88+
* **Tree shake suport** via esm import syntax ([tree-shaking](https://webpack.js.org/guides/tree-shaking/))
8789
* **Pretty Error:** Errors and stack traces printed in a structured way and fully accessible through _JSON_ (e.g. external Log services)
8890
* **Code frame:** `tslog` captures and displays the source code that lead to an error, making it easier to debug
8991
* **Object/JSON highlighting:** Nicely prints out an object using native Node.js `utils.inspect` method

src/Logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export class Logger extends LoggerWithoutCallSite {
1515
super(settings, parentSettings);
1616
this._callSiteWrapper = wrapCallSite;
1717
}
18-
}
18+
}

src/LoggerWithoutCallSite.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { hostname } from "os";
32
import { normalize as fileNormalize } from "path";
43
import { inspect, format } from "util";
@@ -200,7 +199,10 @@ export class LoggerWithoutCallSite {
200199
const childSettings: ISettings = {
201200
...this.settings,
202201
};
203-
const childLogger: Logger = new (this.constructor as any)(settings, childSettings);
202+
const childLogger: Logger = new (this.constructor as any)(
203+
settings,
204+
childSettings
205+
);
204206
this._childLogger.push(childLogger);
205207
return childLogger;
206208
}
@@ -360,7 +362,9 @@ export class LoggerWithoutCallSite {
360362
const relevantCallSites: NodeJS.CallSite[] = callSites.splice(
361363
this.settings.ignoreStackLevels
362364
);
363-
const stackFrame: NodeJS.CallSite = this._callSiteWrapper(relevantCallSites[0]);
365+
const stackFrame: NodeJS.CallSite = this._callSiteWrapper(
366+
relevantCallSites[0]
367+
);
364368
const stackFrameObject: IStackFrame = LoggerHelper.toStackFrameObject(
365369
stackFrame
366370
);
@@ -857,4 +861,4 @@ export class LoggerWithoutCallSite {
857861
? formattedStr.replace(this._maskAnyRegExp, this.settings.maskPlaceholder)
858862
: formattedStr;
859863
}
860-
}
864+
}

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export {
2121
TUtilsInspectColors,
2222
ISettings,
2323
ICodeFrame,
24-
} from './interfaces';
25-
26-
export { Logger } from './Logger';
27-
export { LoggerWithoutCallSite } from './LoggerWithoutCallSite';
24+
} from "./interfaces";
2825

26+
export { Logger } from "./Logger";
27+
export { LoggerWithoutCallSite } from "./LoggerWithoutCallSite";

tests/error.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import "ts-jest";
2-
import { IErrorObject, ILogObject, Logger, LoggerWithoutCallSite } from "../src";
2+
import {
3+
IErrorObject,
4+
ILogObject,
5+
Logger,
6+
LoggerWithoutCallSite,
7+
} from "../src";
38
import { doesLogContain } from "./helper";
49

510
let stdOut: string[] = [];
@@ -20,7 +25,10 @@ const loggerConfig = {
2025

2126
const loggerPretty: Logger = new Logger({ ...loggerConfig, type: "pretty" });
2227
const loggerJson: Logger = new Logger({ ...loggerConfig, type: "json" });
23-
const loggerJsonWithoutCallsite: Logger = new LoggerWithoutCallSite({ ...loggerConfig, type: "json" });
28+
const loggerJsonWithoutCallsite: Logger = new LoggerWithoutCallSite({
29+
...loggerConfig,
30+
type: "json",
31+
});
2432

2533
class TestError extends Error {
2634
constructor(message: string) {

0 commit comments

Comments
 (0)