Skip to content

Commit 23ac524

Browse files
committed
chore: Switch to logger with JSON support
And because I like my own logger more than consola.
1 parent 6aab516 commit 23ac524

11 files changed

Lines changed: 60 additions & 73 deletions

File tree

bun.lock

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

cspell.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ ignorePaths:
44
- src/@types/gql.d.ts
55
- "**/*.snap"
66
words:
7+
- adduser
78
- aklinker
8-
- klinker
9-
- linkedom
10-
- oxlint
11-
- importmap
12-
- ocfdgncpifmegplaglcnglhioflaimkd
9+
- crxid
1310
- grpahql
14-
- libstdc
11+
- importmap
12+
- klinker
1513
- libgcc
16-
- adduser
14+
- libstdc
15+
- linkedom
1716
- microsoftedge
18-
- crxid
17+
- noindexed
18+
- ocfdgncpifmegplaglcnglhioflaimkd
19+
- oxlint

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
"postinstall": "simple-git-hooks"
1717
},
1818
"dependencies": {
19+
"@aklinker1/logger": "^1.0.6",
1920
"@aklinker1/zero-ioc": "^1.5.1",
2021
"@aklinker1/zeta": "^2.2.0",
21-
"consola": "^3.4.2",
2222
"dataloader": "^2.2.3",
2323
"dedent": "^1.7.2",
2424
"graphql": "^16.13.2",
2525
"linkedom": "^0.18.12",
26-
"picocolors": "^1.1.1",
2726
"zod": "^4.3.6"
2827
},
2928
"devDependencies": {

scripts/dev.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#!/usr/bin/env bun
2-
import consola, { LogLevels } from "consola";
32
import app from "../src/server";
43
import { generateGqlTypes } from "./generate-gql-types";
5-
import pc from "picocolors";
64
import { version } from "../package.json";
5+
import { createLogger } from "@aklinker1/logger";
6+
7+
const logger = createLogger("http");
78

89
const fetch = app.build();
910
await generateGqlTypes(fetch);
1011

11-
consola.level = LogLevels.debug;
12-
const port = Number(process.env.PORT ?? "3000");
13-
Bun.serve({ port, fetch });
12+
const server = Bun.serve({ fetch });
1413

15-
consola.success(
16-
`${pc.cyan("@wxt-dev/queue v" + version)} ${pc.dim("server started")}`,
17-
);
18-
consola.log(` ${pc.bold(pc.green("➜"))} http://localhost:${port}`);
19-
console.log();
14+
logger.success("@wxt-dev/queue server started", { version, url: server.url });

scripts/generate-gql-types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import CodeBlockWriter from "code-block-writer";
2-
import { consola } from "consola";
32
import type { ServerSideFetch } from "@aklinker1/zeta/types";
43
import app from "../src/server";
4+
import { createLogger } from "@aklinker1/logger";
5+
6+
const logger = createLogger("gen:gql-types");
57

68
const typesFile = Bun.file("src/@types/gql.d.ts");
79

@@ -13,7 +15,7 @@ const scalarNameToTs = {
1315
};
1416

1517
export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
16-
consola.info("Generating GraphQL types...");
18+
logger.info("Starting...");
1719
const introspection = await introspect(fetch);
1820

1921
const {
@@ -53,7 +55,7 @@ export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
5355
case "INTERFACE":
5456
return writeObjectType(code, argTypes, type);
5557
default:
56-
return consola.warn("Unknown kind:", {
58+
return logger.warn("Unknown kind:", {
5759
kind: type.kind,
5860
name: type.name,
5961
});
@@ -66,7 +68,7 @@ export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
6668
code.newLine();
6769

6870
await Bun.write(typesFile, code.toString());
69-
consola.success("Generated GraphQL types");
71+
logger.success("Done");
7072
}
7173

7274
function capitalizeFirstLetter(str: string): string {
@@ -82,7 +84,7 @@ function getTsTypeString(gqlType: any): string {
8284
if (gqlType.kind === "SCALAR" || gqlType.kind === "OBJECT")
8385
return `${gqlType.name} | undefined`;
8486

85-
consola.warn("Unknown TS type:", gqlType);
87+
logger.warn("Unknown GQL -> TS type", { gqlType });
8688
return "unknown";
8789
}
8890

@@ -124,7 +126,7 @@ function writeScalarType(code: CodeBlockWriter, type: any) {
124126
// @ts-expect-error
125127
const typeStr = scalarNameToTs[type.name];
126128
if (typeStr == null) {
127-
consola.warn("Unknown scalar type:", type);
129+
logger.warn("Unknown scalar type:", { type });
128130
}
129131
code.writeLine(`type ${type.name} = ${typeStr || "unknown"};`);
130132
}

src/graphql/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { buildSchema, graphql } from "graphql";
22
import gqlSchema from "../assets/schema.gql" with { type: "text" };
33
import { rootResolver } from "./resolvers";
4-
import { consola } from "consola";
5-
import pc from "picocolors";
64
import { container } from "../dependencies";
5+
import { createLogger } from "@aklinker1/logger";
6+
7+
const logger = createLogger("gql");
78

89
export function createGraphql() {
910
const schema = buildSchema(gqlSchema);
@@ -15,11 +16,8 @@ export function createGraphql() {
1516
const { operationName = "Unknown", query, variables } = body;
1617

1718
const start = performance.now();
18-
consola.debug(
19-
`${pc.dim(`<-- [${id}]`)} ${pc.green(method)} ${pc.cyan(
20-
pc.bold(operationName),
21-
)}`,
22-
);
19+
20+
logger.debug("Running query", { id, method, operationName });
2321

2422
const response = await graphql({
2523
schema,
@@ -30,11 +28,12 @@ export function createGraphql() {
3028
});
3129

3230
const end = performance.now();
33-
consola.debug(
34-
`${pc.dim(`--> [${id}]`)} ${pc.green(method)} ${pc.cyan(
35-
pc.bold(operationName),
36-
)} ${(end - start).toFixed(3)}ms`,
37-
);
31+
logger.debug("Query finished", {
32+
id,
33+
method,
34+
operationName,
35+
durationMs: end - start,
36+
});
3837

3938
return response;
4039
};

src/main.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
#!/usr/bin/env bun
2-
import consola from "consola";
32
import app from "./server";
4-
import pc from "picocolors";
53
import { version } from "../package.json";
4+
import { createLogger } from "@aklinker1/logger";
65

7-
if (process.env.LOG_LEVEL) {
8-
// silent: Number.NEGATIVE_INFINITY
9-
// fatal: 0
10-
// error: 0
11-
// warn: 1
12-
// log: 2
13-
// info: 3
14-
// success: 3
15-
// fail: 3
16-
// ready: 3
17-
// start: 3
18-
// box: 3
19-
// debug: 4
20-
// trace: 5
21-
// verbose: Number.POSITIVE_INFINITY
22-
consola.level = Number(process.env.LOG_LEVEL);
23-
}
6+
const logger = createLogger("http");
247

258
const port = Number(process.env.PORT ?? "3000");
269
app.listen(port, () => {
27-
consola.info(
28-
`${pc.cyan("@wxt-dev/queue v" + version)} ${pc.dim("server started")}`,
29-
);
10+
logger.success("@wxt-dev/queue started", { version, port });
3011
});

src/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import consola from "consola";
21
import { createApp } from "@aklinker1/zeta";
32
import { corsPlugin } from "./plugins/cors-plugin";
43
import { graphqlApis } from "./apis/graphql-apis";
@@ -8,6 +7,9 @@ import { version } from "./version";
87
import dedent from "dedent";
98
import { systemApis } from "./apis/system-apis";
109
import { OpenApiTag } from "./enums";
10+
import { createLogger } from "@aklinker1/logger";
11+
12+
const logger = createLogger("http");
1113

1214
const app = createApp({
1315
schemaAdapter: zodSchemaAdapter,
@@ -47,7 +49,7 @@ const app = createApp({
4749
],
4850
},
4951
})
50-
.onGlobalError(({ error }) => void consola.error(error))
52+
.onGlobalError(({ error }) => void logger.error("Request error", { error }))
5153
.use(corsPlugin)
5254
.use(systemApis)
5355
.use(extensionStoreApis)

src/services/chrome-crawler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import consola from "consola";
21
import { HTMLAnchorElement, HTMLElement, parseHTML } from "linkedom";
32
import { ExtensionStoreName } from "../enums";
43
import { buildScreenshotUrl } from "../utils/urls";
4+
import { createLogger } from "@aklinker1/logger";
5+
6+
const logger = createLogger("chrome-crawler");
57

68
export async function crawlExtension(
79
id: string,
810
lang: string,
911
canGenerateTestFixture = false,
1012
): Promise<Gql.ChromeExtension | undefined> {
11-
consola.info("Crawling " + id);
13+
logger.info("Start", { id, lang });
1214
const url = `https://chromewebstore.google.com/detail/${id}?hl=${lang}`;
1315
const res = await fetch(url, {
1416
headers: {
@@ -173,7 +175,7 @@ export async function crawlExtension(
173175
reviewCount,
174176
screenshots,
175177
};
176-
consola.debug("Crawl results:", result);
178+
logger.debug("Crawl complete", { id, result });
177179
return result;
178180
}
179181

src/services/edge-api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { createLogger } from "@aklinker1/logger";
12
import { ExtensionStoreName } from "../enums";
23
import { buildScreenshotUrl } from "../utils/urls";
34

5+
const logger = createLogger("edge-api");
6+
47
export interface EdgeApi {
58
getAddon(crxid: string): Promise<Gql.EdgeAddon>;
69
}
@@ -34,6 +37,7 @@ export function createEdgeApi(): EdgeApi {
3437
});
3538

3639
const getAddon: EdgeApi["getAddon"] = async (crxid) => {
40+
logger.info("Get addon", { crxid });
3741
const res = await fetch(
3842
`https://microsoftedge.microsoft.com/addons/getproductdetailsbycrxid/${crxid}`,
3943
);
@@ -42,6 +46,7 @@ export function createEdgeApi(): EdgeApi {
4246
}
4347

4448
const json = (await res.json()) as GetProductDetailsByCrxId200Response;
49+
logger.debug("Addon result", { crxid, json });
4550

4651
return toGqlEdgeAddon(json);
4752
};

0 commit comments

Comments
 (0)