Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

14 changes: 0 additions & 14 deletions build.js

This file was deleted.

14 changes: 14 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { build } from "esbuild";

build({
entryPoints: ["src/index.ts"],
outfile: "dist/browser/index.js",
platform: "browser",
bundle: true,
minify: true,
format: "iife",
globalName: "timbergeist",
loader: { ".ts": "ts" },
})
.then(() => console.log("⚡ Done"))
.catch(() => process.exit(1));
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
node = "22"
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"types": "./dist/types/index.d.ts",
"scripts": {
"build": "npm run build-types && npm run build-server && npm run build-browser",
"build-browser": "node build.js",
"build-browser": "node build.mjs",
"build-types": "tsc -b tsconfig.types.json",
"build-server": "tsc -b tsconfig.cjs.json && cp ./src/package-cjs.json ./dist/cjs/package.json",
"build-example": "tsc -b tsconfig.example.json",
Expand All @@ -19,7 +19,7 @@
"dev-js": "npm run build-example && node --experimental-specifier-resolution=node --enable-source-maps examples/dist/examples/nodejs/index2.js",
"lint": "eslint --ext .js,.ts .",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
"test": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest && yarn ts-node tests/RAW/stack_trace.test.ts",
"test": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest",
"test-puppeteer-serve": "npm run build-browser && node tests/Browser/server/index.cjs -p 4444",
"coverage": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest --coverage",
"docsify-init": "docsify init ./docs",
Expand All @@ -30,7 +30,7 @@
"release:npm": "yarn prerelease && yarn publish --no-git-tag-version --access public"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"jest": {
"verbose": true,
Expand Down
25 changes: 4 additions & 21 deletions tests/Browser/1_json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,10 @@ describe("Browser: JSON: Log level", () => {
await expect(html).toContain("tslog Demo");
});

it("silly", async () => {
await page.evaluate(() => {
// @ts-ignore
const logger = new tslog.Logger({ type: "json" });
logger.silly("Test");
});

expect(consoleOutput).toContain('"0":"Test"');
expect(consoleOutput).toContain('"_meta":{');
expect(consoleOutput).toContain('"runtime":"Browser"');
expect(consoleOutput).toContain(`"date":"${new Date().toISOString().split(".")[0]}`); // ignore ms
expect(consoleOutput).toContain('"logLevelId":0');
expect(consoleOutput).toContain('"logLevelName":"SILLY"');
expect(consoleOutput).toContain('"path":{');
expect(consoleOutput).toContain('"fileLine":"22"');
});

it("pretty", async () => {
await page.evaluate(() => {
// @ts-ignore
const logger = new tslog.Logger({ type: "pretty" });
const logger = new timbergeist.Logger({ type: "pretty" });
logger.silly("Test");
});

Expand All @@ -49,7 +32,7 @@ describe("Browser: JSON: Log level", () => {
it("pretty no styles", async () => {
await page.evaluate(() => {
// @ts-ignore
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
const logger = new timbergeist.Logger({ type: "pretty", stylePrettyLogs: false });
logger.silly("Test");
});

Expand All @@ -59,7 +42,7 @@ describe("Browser: JSON: Log level", () => {
it("pretty no styles undefined", async () => {
await page.evaluate(() => {
// @ts-ignore
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
const logger = new timbergeist.Logger({ type: "pretty", stylePrettyLogs: false });
logger.fatal("Test undefined", { test: undefined });
});

Expand All @@ -69,7 +52,7 @@ describe("Browser: JSON: Log level", () => {
it("pretty string interpolation", async () => {
await page.evaluate(() => {
// @ts-ignore
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
const logger = new timbergeist.Logger({ type: "pretty", stylePrettyLogs: false });
logger.info("Foo %s", "bar");
});

Expand Down
22 changes: 17 additions & 5 deletions tests/Nodejs/11_Transports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ describe("Transports", () => {
transports.push(logObj);
}});

const logMsg = logger.info("string", 0, { test: 123 });
logger.info("string", 0, { test: 123 });

expect(logMsg).toMatchObject(transports[0]);
expect(transports[0]).toMatchObject({
"0": "string",
"1": 0,
"2": { test: 123 },
});
});

test("attach two transport", (): void => {
Expand All @@ -24,9 +28,17 @@ describe("Transports", () => {
transports.push(logObj);
}});

const logMsg = logger.info("string", 0, { test: 123 });
logger.info("string", 0, { test: 123 });

expect(logMsg).toMatchObject(transports[0]);
expect(logMsg).toMatchObject(transports[1]);
expect(transports[0]).toMatchObject({
"0": "string",
"1": 0,
"2": { test: 123 },
});
expect(transports[1]).toMatchObject({
"0": "string",
"1": 0,
"2": { test: 123 },
});
});
});
56 changes: 23 additions & 33 deletions tests/Nodejs/12_SubLoggers_and_Prefixes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,35 @@ import { Logger } from "../../src/index.js";

describe("SubLoggers", () => {
test("one sub logger", (): void => {
const transports: any[] = [];
const mainLogger = new Logger();
const logMsg = mainLogger.info("main logger");
expect(logMsg?.["0"]).toBe("main logger");
mainLogger.attachTransport({ transport: (logObj) => {
transports.push(logObj);
}});
mainLogger.info("main logger");
expect(transports[0]).toMatchObject({
"0": "main logger",
});

const subLogger = mainLogger.getSubLogger();
const subLogMsg = subLogger.info("sub logger");
expect(subLogMsg?.["0"]).toBe("sub logger");
subLogger.info("sub logger");
expect(transports[1]).toMatchObject({
"0": "sub logger",
});
});

test("one sub logger with prefix", (): void => {
const mainLogger = new Logger({ type: "hidden", prefix: ["main"] });
const logMsg = mainLogger.info("test-main");
expect(logMsg?.["0"]).toBe("main");
expect(logMsg?.["1"]).toBe("test-main");
const loggerNames: any[] = [];
const mainLogger = new Logger({ name: "main" });
mainLogger.attachTransport({ transport: (logArgs, logMeta) => {
loggerNames.push(logMeta);
}});
mainLogger.info("test-main");
expect(loggerNames[0].name).toBe("main");

const subLogger = mainLogger.getSubLogger({ type: "hidden", prefix: ["sub"] });
const subLogMsg = subLogger.info("test-sub");
expect(subLogMsg?.["0"]).toBe("main");
expect(subLogMsg?.["1"]).toBe("sub");
expect(subLogMsg?.["2"]).toBe("test-sub");
});

test("sub logger overwriting LogObj", (): void => {
const mainLogObj = {
main: true,
sub: false,
};
const mainLogger = new Logger({ type: "hidden" }, mainLogObj);
const logMsg = mainLogger.info("main logger");
expect(logMsg?.main).toBe(true);
expect(logMsg?.sub).toBe(false);

const subLogObj = {
main: false,
sub: true,
};
const subLogger = mainLogger.getSubLogger({ type: "hidden" }, subLogObj);
const subLogMsg = subLogger.info("test-sub");
expect(subLogMsg?.main).toBe(false);
expect(subLogMsg?.sub).toBe(true);
const subLogger = mainLogger.getSubLogger({ name: "sub" });
subLogger.info("test-sub");
expect(loggerNames[1].name).toBe("sub");
expect(loggerNames[1].parentNames).toContain("main");
});
});
66 changes: 5 additions & 61 deletions tests/Nodejs/13_Recursive.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,14 @@
import "ts-jest";
import { Logger } from "../../src/index.js";
import { mockConsoleLog } from "./helper.js";
import { getConsoleOutput, mockConsoleLog } from "./helper.js";

describe("Recursive", () => {
beforeEach(() => {
mockConsoleLog(true, false);
});

test("hidden", (): void => {
const mainLogger = new Logger({ type: "hidden" });

/*
* Circular example
* */
function Foo() {
/* @ts-ignore */
this.abc = "Hello";
/* @ts-ignore */
this.circular = this;
}
/* @ts-ignore */
const foo = new Foo();
const logMsg = mainLogger.info("circular", foo);
expect(logMsg?.["0"]).toBe("circular");
expect(logMsg?.["1"]["circular"]).toEqual(logMsg?.["1"]);
});

test("json", (): void => {
const mainLogger = new Logger({ type: "json" });

/*
* Circular example
* */
function Foo() {
/* @ts-ignore */
this.abc = "Hello";
/* @ts-ignore */
this.circular = this;
}
/* @ts-ignore */
const foo = new Foo();
const logMsg = mainLogger.info("circular", foo);
expect(logMsg?.["0"]).toBe("circular");
expect(logMsg?.["1"]["circular"]).toEqual(logMsg?.["1"]);
});

test("pretty", (): void => {
const mainLogger = new Logger({ type: "pretty" });
const mainLogger = new Logger();

/*
* Circular example
Expand All @@ -59,26 +21,8 @@ describe("Recursive", () => {
}
/* @ts-ignore */
const foo = new Foo();
const logMsg = mainLogger.info("circular", foo);
expect(logMsg?.["0"]).toBe("circular");
expect(logMsg?.["1"]["circular"]).toEqual(logMsg?.["1"]);
});

test("pretty recursive LogObj function", (): void => {
/*
* Circular example
* */
function Foo() {
/* @ts-ignore */
this.abc = "Hello";
/* @ts-ignore */
this.circular = this;
}
/* @ts-ignore */
const foo = new Foo();
const mainLogger = new Logger({ type: "pretty" }, foo);

const logMsg = mainLogger.info("circular");
expect(logMsg?.["0"]).toBe("circular");
mainLogger.info("circular", foo);
expect(getConsoleOutput()).toContain("circular");
expect(getConsoleOutput()).toContain("Hello");
});
});
17 changes: 4 additions & 13 deletions tests/Nodejs/14_Getters_Setters.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "ts-jest";
import { ok } from "assert";
import { Logger } from "../../src/index.js";
import { getConsoleOutput, mockConsoleLog } from "./helper.js";

Expand All @@ -22,23 +21,15 @@ describe("Getters and setters", () => {

test("[class] should not print getters on class instance (prototype)", (): void => {
// Node.js issue: https://github.com/nodejs/node/issues/30183
const logger = new Logger({
type: "pretty",
});
const logger = new Logger();
const missingSetterObj = new MissingSetter();
const result = logger.info(missingSetterObj);
ok(result);
expect(Object.keys(result)).not.toContain("testProp");
logger.info(missingSetterObj);
expect(getConsoleOutput()).not.toContain("testProp");
});

test("[object] should print getters", (): void => {
const logger = new Logger({
type: "pretty",
});
const result = logger.info(missingSetter);
ok(result);
expect(Object.keys(result)).toContain("testProp");
const logger = new Logger();
logger.info(missingSetter);
expect(getConsoleOutput()).toContain("testProp");
});
});
2 changes: 1 addition & 1 deletion tests/Nodejs/5_pretty_Log_Types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Pretty: Log Types", () => {
});

test("Object, String", (): void => {
const logger = new Logger();
const logger = new Logger({}, [new PrettyPrinterTransport(ConsoleSink, { stylePrettyLogs: false })]);
logger.log(1234, "testLevel", { test: true, nested: { 1: false } }, "test");
expect(getConsoleOutput()).toContain("{ test: true, nested: { '1': false } } test");
});
Expand Down
Loading