Skip to content

Commit f42d3fb

Browse files
authored
Merge pull request #290 from fullstack-build/development
Bugfix and dependency updates
2 parents f7474a3 + c7fd912 commit f42d3fb

12 files changed

Lines changed: 130 additions & 14 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ logger.fatal(new Error("I am a pretty Error with a stacktrace."));
167167
## All Features
168168

169169
- **Universal:** Works in browsers and Node.js
170-
- **Tested:** 100% code coverage, CI
170+
- **Tested:** Great code coverage, CI
171171
- **Super customizable:** Every aspect can be overwritten
172172
- **Fully typed:** Written in TypeScript, with native TypeScript support
173173
- **Default log level:** `silly`, `trace`, `debug`, `info`, `warn`, `error`, `fatal` (different colors)

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ logger.fatal(new Error("I am a pretty Error with a stacktrace."));
167167
## All Features
168168

169169
- **Universal:** Works in browsers and Node.js
170-
- **Tested:** 100% code coverage, CI
170+
- **Tested:** Great code coverage, CI
171171
- **Super customizable:** Every aspect can be overwritten
172172
- **Fully typed:** Written in TypeScript, with native TypeScript support
173173
- **Default log level:** `silly`, `trace`, `debug`, `info`, `warn`, `error`, `fatal` (different colors)
@@ -686,7 +686,7 @@ For `pretty` logs:
686686
For `JSON` logs (no formatting happens here):
687687
```typescript
688688
const logger = new Logger({
689-
type: "pretty",
689+
type: "json",
690690
overwrite: {
691691
transportJSON: (logObjWithMeta: any) => {
692692
// transport the LogObj to console, StdOut, a file or an external service

examples/nodejs/index2.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@ class CustomError extends Error {
119119

120120
const err = new CustomError("a", "b");
121121
logger.error(err);
122+
123+
console.log("***********");
124+
logger.debug(null);
125+
logger.debug(undefined);
126+
logger.debug("*", undefined);
127+
console.log("###############");
128+
//jsonLogger.debug(null);
129+
jsonLogger.debug(undefined);
130+
//jsonLogger.debug('*', undefined);
131+
console.log("###############");
132+
logger.debug(new URL("https://www.test.de"));

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tslog",
3-
"version": "4.9.1",
3+
"version": "4.9.2",
44
"description": "Extensible TypeScript Logger for Node.js and Browser.",
55
"author": "Eugene <opensource@terehov.de> (https://fullstack.build)",
66
"license": "MIT",

src/BaseLogger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ export class BaseLogger<LogObj> {
213213
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
214214
o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
215215
? this.settings.maskPlaceholder
216-
: this._recursiveCloneAndMaskValuesOfKeys((source as Record<string, unknown>)[prop], keys, seen);
216+
: (() => {
217+
try {
218+
return this._recursiveCloneAndMaskValuesOfKeys((source as Record<string, unknown>)[prop], keys, seen);
219+
} catch (e) {
220+
return null;
221+
}
222+
})();
217223
return o;
218224
}, baseObject) as T;
219225
} else {

src/runtime/browser/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export function getCallerStackFrame(stackDepthLevel: number, error: Error = Erro
6262
}
6363

6464
export function getErrorTrace(error: Error): IStackFrame[] {
65-
return (error as Error)?.stack
66-
?.split("\n")
65+
return ((error as Error)?.stack?.split("\n") ?? [])
6766
?.filter((line: string) => !line.includes("Error: "))
6867
?.reduce((result: IStackFrame[], line: string) => {
6968
result.push(stackLineToStackFrame(line));

src/runtime/browser/util.inspect.polyfil.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function isBoolean(arg: unknown) {
6363
}
6464

6565
function isUndefined(arg: unknown) {
66-
return arg == null;
66+
return arg === undefined;
6767
}
6868

6969
function stylizeNoColor(str: string) {
@@ -377,19 +377,19 @@ function reduceToSingleString(output: string[], base: string, braces: string[]):
377377
return braces[0] + (base === "" ? "" : base + "\n") + " " + output.join(",\n ") + " " + braces[1];
378378
}
379379

380-
function _extend(origin: object, add: object) {
380+
function _extend(origin: object, add: object): object {
381+
const typedOrigin = { ...origin } as { [key: string]: unknown };
381382
// Don't do anything if add isn't an object
382383
if (!add || !isObject(add)) return origin;
383384

384-
const clonedOrigin = { ...origin } as { [key: string]: unknown };
385385
const clonedAdd = { ...add } as { [key: string]: unknown };
386386

387387
const keys = Object.keys(add);
388388
let i = keys.length;
389389
while (i--) {
390-
clonedOrigin[keys[i]] = clonedAdd[keys[i]];
390+
typedOrigin[keys[i]] = clonedAdd[keys[i]];
391391
}
392-
return origin;
392+
return typedOrigin;
393393
}
394394

395395
export function formatWithOptions(inspectOptions: InspectOptions, ...args: unknown[]) {

src/runtime/nodejs/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export function transportJSON<LogObj>(json: LogObj & ILogObjMeta): void {
168168
if (typeof value === "bigint") {
169169
return `${value}`;
170170
}
171+
if (typeof value === "undefined") {
172+
return "[undefined]";
173+
}
171174
return value;
172175
});
173176
}

tests/Browser/1_json.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,32 @@ describe("Browser: JSON: Log level", () => {
7575

7676
expect(consoleOutput).toContain("Foo bar");
7777
});
78+
79+
it("pretty undefined", async () => {
80+
await page.evaluate(() => {
81+
// @ts-ignore
82+
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
83+
logger.info(undefined);
84+
});
85+
expect(consoleOutput).toContain("undefined");
86+
});
87+
88+
it("pretty null", async () => {
89+
await page.evaluate(() => {
90+
// @ts-ignore
91+
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
92+
logger.info(null);
93+
});
94+
expect(consoleOutput).toContain("null");
95+
});
96+
97+
it("pretty nullish", async () => {
98+
await page.evaluate(() => {
99+
// @ts-ignore
100+
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
101+
logger.info({ foo: null, bar: undefined });
102+
});
103+
expect(consoleOutput).toContain("null");
104+
expect(consoleOutput).toContain("undefined");
105+
});
78106
});

0 commit comments

Comments
 (0)