Skip to content

Commit

Permalink
Add tree shaking to feature set in README
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Nov 11, 2020
1 parent a97d463 commit da01760
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
👨‍👧‍👦 **Child logger with inheritance**<br>
🙊 **Mask/hide secrets and keys**<br>
🔍 **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>
🌳 **Tree shaking support**<br>
🧲 **Optionally catch all `console` logs**<br>
✍️ **well documented**<br>

Expand Down Expand Up @@ -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 <a href="https://api-extractor.com" target="_blank">_api-extractor_</a>, <a href="https://github.com/microsoft/tsdoc" target="_blank">_TSDoc_</a> documented
* **Source maps lookup:** Shows exact position also in TypeScript code (compile-to-JS), one click to IDE position
* **Stack trace:** Callsites through native <a href="https://v8.dev/docs/stack-trace-api" target="_blank">_V8 stack trace API_</a>, 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
Expand Down
2 changes: 1 addition & 1 deletion src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export class Logger extends LoggerWithoutCallSite {
super(settings, parentSettings);
this._callSiteWrapper = wrapCallSite;
}
}
}
12 changes: 8 additions & 4 deletions src/LoggerWithoutCallSite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { hostname } from "os";
import { normalize as fileNormalize } from "path";
import { inspect, format } from "util";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -857,4 +861,4 @@ export class LoggerWithoutCallSite {
? formattedStr.replace(this._maskAnyRegExp, this.settings.maskPlaceholder)
: formattedStr;
}
}
}
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
12 changes: 10 additions & 2 deletions tests/error.test.ts
Original file line number Diff line number Diff line change
@@ -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[] = [];
Expand All @@ -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) {
Expand Down

0 comments on commit da01760

Please sign in to comment.