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

File tree

12 files changed

+130
-14
lines changed

12 files changed

+130
-14
lines changed

Diff for: README.md

+1-1
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)

Diff for: docs/README.md

+2-2
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

Diff for: examples/nodejs/index2.ts

+11
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"));

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
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 <[email protected]> (https://fullstack.build)",
66
"license": "MIT",

Diff for: src/BaseLogger.ts

+7-1
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 {

Diff for: src/runtime/browser/index.ts

+1-2
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));

Diff for: src/runtime/browser/util.inspect.polyfil.ts

+5-5
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[]) {

Diff for: src/runtime/nodejs/index.ts

+3
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
}

Diff for: tests/Browser/1_json.test.ts

+28
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
});

Diff for: tests/Nodejs/4_json_Log_Types.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ describe("JSON: Log Types", () => {
2020
expect(getConsoleLog()).toContain('"1":"Test2"');
2121
});
2222

23+
it("pretty undefined", async () => {
24+
const logger = new Logger({ type: "json" });
25+
logger.info(undefined);
26+
expect(getConsoleLog()).toContain('"0":"[undefined]"');
27+
});
28+
29+
it("pretty null", async () => {
30+
const logger = new Logger({ type: "json" });
31+
logger.info(null);
32+
expect(getConsoleLog()).toContain('"0":null');
33+
});
34+
35+
it("pretty nullish", async () => {
36+
const logger = new Logger({ type: "json" });
37+
logger.info({ foo: null, bar: undefined });
38+
39+
expect(getConsoleLog()).toContain('"foo":null');
40+
expect(getConsoleLog()).toContain('"bar":"[undefined]"');
41+
});
42+
2343
test("boolean", (): void => {
2444
const logger = new Logger({ type: "json" });
2545
logger.log(1234, "testLevel", true);

Diff for: tests/Nodejs/5_pretty_Log_Types.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ describe("Pretty: Log Types", () => {
3333
expect(getConsoleLog()).toContain("Test1 Test2");
3434
});
3535

36+
it("pretty undefined", async () => {
37+
const logger = new Logger({ type: "pretty", stylePrettyLogs: false });
38+
logger.info(undefined);
39+
40+
expect(getConsoleLog()).toContain("undefined");
41+
});
42+
43+
it("pretty null", async () => {
44+
const logger = new Logger({ type: "pretty", stylePrettyLogs: false });
45+
logger.info(null);
46+
47+
expect(getConsoleLog()).toContain("null");
48+
});
49+
50+
it("pretty nullish", async () => {
51+
const logger = new Logger({ type: "pretty", stylePrettyLogs: false });
52+
logger.info({ foo: null, bar: undefined });
53+
54+
expect(getConsoleLog()).toContain("null");
55+
expect(getConsoleLog()).toContain("undefined");
56+
});
57+
3658
test("boolean", (): void => {
3759
const logger = new Logger({ type: "pretty" });
3860
logger.log(1234, "testLevel", true);
@@ -45,6 +67,12 @@ describe("Pretty: Log Types", () => {
4567
expect(getConsoleLog()).toContain("555");
4668
});
4769

70+
test("null", (): void => {
71+
const logger = new Logger({ type: "pretty" });
72+
logger.log(1234, "testLevel", null);
73+
expect(getConsoleLog()).toContain("null");
74+
});
75+
4876
test("Array, stylePrettyLogs: false", (): void => {
4977
const logger = new Logger({ type: "pretty", stylePrettyLogs: false });
5078
logger.log(1234, "testLevel", [1, 2, 3, "test"]);
@@ -94,6 +122,27 @@ describe("Pretty: Log Types", () => {
94122
expect(getConsoleLog()).toContain("https://example2.com/");
95123
});
96124

125+
test("Date", (): void => {
126+
const logger = new Logger({ type: "pretty" });
127+
const date = new Date(0);
128+
logger.log(1234, "testLevel", date);
129+
expect(getConsoleLog()).toContain("1970-01-01T00:00:00.000Z");
130+
});
131+
132+
test("Map", (): void => {
133+
const logger = new Logger({ type: "pretty" });
134+
const map = new Map();
135+
logger.log(1234, "testLevel", map);
136+
expect(getConsoleLog()).toContain("Map(0) {}");
137+
});
138+
139+
test("Set", (): void => {
140+
const logger = new Logger({ type: "pretty" });
141+
const set = new Set();
142+
logger.log(1234, "testLevel", set);
143+
expect(getConsoleLog()).toContain("Set(0) {}");
144+
});
145+
97146
test("String, Object", (): void => {
98147
const logger = new Logger({ type: "pretty" });
99148
logger.log(1234, "testLevel", "test", { test: true, nested: { 1: false } });

0 commit comments

Comments
 (0)