@witchcraft/nuxt-logger 0.0.11 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/dist/module.json +3 -3
- package/dist/module.mjs +4 -3
- package/dist/runtime/electron/index.d.ts +1 -4
- package/dist/runtime/electron/index.js +0 -3
- package/dist/runtime/electron/main/index.d.ts +3 -0
- package/dist/runtime/electron/main/index.js +3 -0
- package/dist/runtime/electron/{receiveFromRendererOnMain.js → main/receiveFromRendererOnMain.js} +1 -1
- package/dist/runtime/electron/{useElectronLogger.d.ts → main/useElectronLogger.d.ts} +2 -1
- package/dist/runtime/electron/{useElectronLogger.js → main/useElectronLogger.js} +3 -3
- package/dist/runtime/electron/{createElectronLoggerApi.d.ts → preload/createElectronLoggerApi.d.ts} +1 -1
- package/dist/runtime/electron/{createElectronLoggerApi.js → preload/createElectronLoggerApi.js} +1 -1
- package/dist/runtime/electron/preload/index.d.ts +1 -0
- package/dist/runtime/electron/preload/index.js +1 -0
- package/dist/runtime/shared/createUseLogger.js +12 -2
- package/package.json +18 -10
- package/src/module.ts +4 -3
- package/src/runtime/electron/index.ts +1 -6
- package/src/runtime/electron/main/index.ts +3 -0
- package/src/runtime/electron/{receiveFromRendererOnMain.ts → main/receiveFromRendererOnMain.ts} +2 -1
- package/src/runtime/electron/{useElectronLogger.ts → main/useElectronLogger.ts} +3 -3
- package/src/runtime/electron/{wrapLoggerForElectron.ts → main/wrapLoggerForElectron.ts} +4 -4
- package/src/runtime/electron/{createElectronLoggerApi.ts → preload/createElectronLoggerApi.ts} +2 -3
- package/src/runtime/electron/preload/index.ts +1 -0
- package/src/runtime/shared/createUseLogger.ts +12 -2
- /package/dist/runtime/electron/{receiveFromRendererOnMain.d.ts → main/receiveFromRendererOnMain.d.ts} +0 -0
- /package/dist/runtime/electron/{wrapLoggerForElectron.d.ts → main/wrapLoggerForElectron.d.ts} +0 -0
- /package/dist/runtime/electron/{wrapLoggerForElectron.js → main/wrapLoggerForElectron.js} +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @witchcraft/nuxt-logger
|
|
2
2
|
|
|
3
|
+
[![Docs][docs-src]][docs-href]
|
|
4
|
+
[![Release][release-src]][release-href]
|
|
3
5
|
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
-
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
6
|
[![License][license-src]][license-href]
|
|
6
7
|
[![Nuxt][nuxt-src]][nuxt-href]
|
|
7
8
|
|
|
@@ -41,6 +42,14 @@ By default redacts some known sensitive keys for the middleware logging requests
|
|
|
41
42
|
|
|
42
43
|
Also redacts the `redact` key, but only in production, so you can put anything semi-sensitive in there that you need to inspect in development.
|
|
43
44
|
|
|
45
|
+
### Server transports
|
|
46
|
+
|
|
47
|
+
On the server the module adds two transports by default, file logging to `logPath` and pretty console logs through `pino-pretty`.
|
|
48
|
+
|
|
49
|
+
Pino resolves the pretty transport at runtime from your app, not from this package. With strict dependency isolation (pnpm) or a bundled server (Nitro), that lookup fails and the server crashes with `unable to determine transport target for "pino-pretty"`. Give the app a copy it can find by adding `pino-pretty` to your app dependencies, or turn the pretty transport off with `disabledServerTransportTargets: ["pino-pretty"]`.
|
|
50
|
+
|
|
51
|
+
In dev the module warns and keeps running without pretty console logs when `pino-pretty` cannot be resolved.
|
|
52
|
+
|
|
44
53
|
### Electron
|
|
45
54
|
|
|
46
55
|
The electron logger requires a bit of setup since electron's main cannot be passed the runtime config normally.
|
|
@@ -51,7 +60,8 @@ This assumes the usage of
|
|
|
51
60
|
There is a full example in the [@witchcraft/nuxt-electron playground](TODO).
|
|
52
61
|
|
|
53
62
|
```ts [main.ts]
|
|
54
|
-
import {
|
|
63
|
+
import { useDevDataDir } from "@witchcraft/nuxt-electron/electron/main"
|
|
64
|
+
import { STATIC } from "@witchcraft/nuxt-electron/electron"
|
|
55
65
|
import { ELECTRON } from "@witchcraft/nuxt-logger/electron"
|
|
56
66
|
|
|
57
67
|
// assuming you stick your active window instances here
|
|
@@ -83,7 +93,7 @@ We can setup the apis for two way communication in the preload script.
|
|
|
83
93
|
```ts
|
|
84
94
|
// preload.ts
|
|
85
95
|
import { contextBridge, ipcRenderer } from "electron"
|
|
86
|
-
import { createElectronLoggerApi, type ElectronLoggerApi } from "@witchcraft/nuxt-logger/electron"
|
|
96
|
+
import { createElectronLoggerApi, type ElectronLoggerApi } from "@witchcraft/nuxt-logger/electron/preload"
|
|
87
97
|
|
|
88
98
|
declare global {
|
|
89
99
|
interface Window {
|
|
@@ -132,12 +142,13 @@ useLogger().debug({ns: "hello"}) // will also get forwarded if redirectAll is tr
|
|
|
132
142
|
|
|
133
143
|
|
|
134
144
|
<!-- Badges -->
|
|
145
|
+
[docs-src]: https://github.com/witchcraftjs/nuxt-logger/actions/workflows/docs.yml/badge.svg
|
|
146
|
+
[docs-href]: https://github.com/witchcraftjs/nuxt-logger/actions/workflows/docs.yml
|
|
147
|
+
[release-src]: https://github.com/witchcraftjs/nuxt-logger/actions/workflows/release.yml/badge.svg
|
|
148
|
+
[release-href]: https://github.com/witchcraftjs/nuxt-logger/actions/workflows/release.yml
|
|
135
149
|
[npm-version-src]: https://img.shields.io/npm/v/@witchcraft/nuxt-logger/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
136
150
|
[npm-version-href]: https://npmjs.com/package/@witchcraft/nuxt-logger
|
|
137
151
|
|
|
138
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@witchcraft/nuxt-logger.svg?style=flat&colorA=020420&colorB=00DC82
|
|
139
|
-
[npm-downloads-href]: https://npmjs.com/package/@witchcraft/nuxt-logger
|
|
140
|
-
|
|
141
152
|
[license-src]: https://img.shields.io/npm/l/@witchcraft/nuxt-logger.svg?style=flat&colorA=020420&colorB=00DC82
|
|
142
153
|
[license-href]: https://npmjs.com/package/@witchcraft/nuxt-logger
|
|
143
154
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -81,9 +81,10 @@ const module$1 = defineNuxtModule({
|
|
|
81
81
|
addPlugin(resolve("./runtime/plugins/init"));
|
|
82
82
|
nuxt.options.alias["#logger"] = resolve("./runtime");
|
|
83
83
|
nuxt.hook("vite:extendConfig", (config) => {
|
|
84
|
-
config.optimizeDeps
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const optimizeDeps = config.optimizeDeps ?? {};
|
|
85
|
+
optimizeDeps.include ??= [];
|
|
86
|
+
optimizeDeps.include.push("pino");
|
|
87
|
+
Object.assign(config, { optimizeDeps });
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
});
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { useElectronLogger } from "./useElectronLogger";
|
|
3
|
-
export { wrapLoggerForElectron } from "./wrapLoggerForElectron";
|
|
4
|
-
export * from "./types";
|
|
1
|
+
export * from "./types.js";
|
package/dist/runtime/electron/{receiveFromRendererOnMain.js → main/receiveFromRendererOnMain.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ipcMain } from "electron";
|
|
2
|
-
import { ELECTRON_LOG_TYPE } from "
|
|
2
|
+
import { ELECTRON_LOG_TYPE } from "../types.js";
|
|
3
3
|
export function receiveFromRendererOnMain(logger) {
|
|
4
4
|
ipcMain.on(ELECTRON_LOG_TYPE.TO_MAIN, (_event, message) => {
|
|
5
5
|
if (typeof message.data === "object" && typeof message.level === "string") {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PublicRuntimeConfig } from "@nuxt/schema";
|
|
2
2
|
import { type BrowserWindow } from "electron";
|
|
3
|
+
import pino from "pino";
|
|
3
4
|
/**
|
|
4
5
|
* A simplified wrapper around pino for use in electron main. Note that it does not support child logger and is actually a simple wrapper around just the basic levels.
|
|
5
6
|
*
|
|
@@ -15,4 +16,4 @@ import { type BrowserWindow } from "electron";
|
|
|
15
16
|
*/
|
|
16
17
|
export declare function useElectronLogger(pinoConfig?: PublicRuntimeConfig["logger"], windows?: () => BrowserWindow[], { receiveFromRenderer }?: {
|
|
17
18
|
receiveFromRenderer?: boolean;
|
|
18
|
-
}): Record<keyof
|
|
19
|
+
}): Record<keyof pino.BaseLogger | keyof pino.LoggerExtras<never, boolean> | "customLevels" | "useOnlyCustomLevels", (data: any) => void>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { keys } from "@alanscodelog/utils/keys";
|
|
2
2
|
import { app } from "electron";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import
|
|
4
|
+
import pino from "pino";
|
|
5
5
|
import { receiveFromRendererOnMain } from "./receiveFromRendererOnMain.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { getBaseOptions } from "../../helpers/getBaseOptions.js";
|
|
7
|
+
import { ELECTRON_LOG_TYPE } from "../types.js";
|
|
8
8
|
globalThis.__bundlerPathsOverrides = {
|
|
9
9
|
"pino-worker": `./node_modules/pino/lib/worker.js`,
|
|
10
10
|
"pino-worker-pipeline": `./node_modules/pino/lib/worker-pipeline.js`,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createElectronLoggerApi, type ElectronLoggerApi } from "./createElectronLoggerApi.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createElectronLoggerApi } from "./createElectronLoggerApi.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pino from "pino";
|
|
2
2
|
import { getBaseOptions } from "../helpers/getBaseOptions.js";
|
|
3
3
|
const logger = {};
|
|
4
4
|
export function createUseLogger(rc, serverPathResolver) {
|
|
@@ -14,7 +14,17 @@ export function createUseLogger(rc, serverPathResolver) {
|
|
|
14
14
|
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger, serverPathResolver);
|
|
15
15
|
let transport;
|
|
16
16
|
if (import.meta.server) {
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
transport = pino.transport(transports);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
const missingTarget = /unable to determine transport target for "([^"]+)"/.exec(e?.message ?? "")?.[1];
|
|
21
|
+
if (import.meta.dev && missingTarget === "pino-pretty") {
|
|
22
|
+
console.warn(`[nuxt-logger] "pino-pretty" could not be resolved, pretty console logs are disabled. Add "pino-pretty" to your app dependencies or set disabledServerTransportTargets: ["pino-pretty"].`);
|
|
23
|
+
transport = pino.transport({ targets: transports.targets.filter((t) => t.target !== "pino-pretty") });
|
|
24
|
+
} else {
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
const pinoLogger = pino(
|
|
20
30
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-logger",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Nuxt module for logging.",
|
|
5
5
|
"repository": "witchcraftjs/nuxt-logger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,13 +11,21 @@
|
|
|
11
11
|
"types": "./dist/types.d.mts",
|
|
12
12
|
"import": "./dist/module.mjs"
|
|
13
13
|
},
|
|
14
|
-
"./*": {
|
|
15
|
-
"types": "./dist/runtime/*.d.ts",
|
|
16
|
-
"import": "./dist/runtime/*.js"
|
|
17
|
-
},
|
|
18
14
|
"./electron": {
|
|
19
15
|
"types": "./dist/runtime/electron/index.d.ts",
|
|
20
16
|
"import": "./dist/runtime/electron/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./electron/main": {
|
|
19
|
+
"types": "./dist/runtime/electron/main/index.d.ts",
|
|
20
|
+
"import": "./dist/runtime/electron/main/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./electron/preload": {
|
|
23
|
+
"types": "./dist/runtime/electron/preload/index.d.ts",
|
|
24
|
+
"import": "./dist/runtime/electron/preload/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./*": {
|
|
27
|
+
"types": "./dist/runtime/*.d.ts",
|
|
28
|
+
"import": "./dist/runtime/*.js"
|
|
21
29
|
}
|
|
22
30
|
},
|
|
23
31
|
"files": [
|
|
@@ -30,18 +38,18 @@
|
|
|
30
38
|
"pino-pretty": "^11.2.2"
|
|
31
39
|
},
|
|
32
40
|
"dependencies": {
|
|
33
|
-
"@alanscodelog/tsconfigs": "^6.
|
|
34
|
-
"@alanscodelog/utils": "^6.0
|
|
41
|
+
"@alanscodelog/tsconfigs": "^6.3.1",
|
|
42
|
+
"@alanscodelog/utils": "^6.3.0",
|
|
35
43
|
"@nuxt/kit": "^4.3.1",
|
|
36
44
|
"defu": "latest",
|
|
37
45
|
"pino": "^9.9.0",
|
|
38
46
|
"pino-pretty": "^11.3.0"
|
|
39
47
|
},
|
|
40
48
|
"devDependencies": {
|
|
41
|
-
"@alanscodelog/eslint-config": "^6.3.
|
|
42
|
-
"@alanscodelog/semantic-release-config": "^6.0.
|
|
49
|
+
"@alanscodelog/eslint-config": "^6.3.2",
|
|
50
|
+
"@alanscodelog/semantic-release-config": "^6.0.3",
|
|
43
51
|
"@nuxt/eslint-config": "^1.15.2",
|
|
44
|
-
"@nuxt/module-builder": "^1.0.
|
|
52
|
+
"@nuxt/module-builder": "^1.0.3",
|
|
45
53
|
"@nuxt/schema": "^4.3.1",
|
|
46
54
|
"@nuxt/test-utils": "^3.19.2",
|
|
47
55
|
"@types/node": "latest",
|
package/src/module.ts
CHANGED
|
@@ -171,9 +171,10 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
171
171
|
nuxt.options.alias["#logger"] = resolve("./runtime")
|
|
172
172
|
nuxt.hook("vite:extendConfig", config => {
|
|
173
173
|
// fixes https://github.com/nuxt/nuxt/issues/13247 partially (also transpiling it breaks it)
|
|
174
|
-
config.optimizeDeps
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
const optimizeDeps = config.optimizeDeps ?? {}
|
|
175
|
+
optimizeDeps.include ??= []
|
|
176
|
+
optimizeDeps.include.push("pino")
|
|
177
|
+
Object.assign(config, { optimizeDeps })
|
|
177
178
|
})
|
|
178
179
|
}
|
|
179
180
|
})
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createElectronLoggerApi, type ElectronLoggerApi } from "./createElectronLoggerApi"
|
|
3
|
-
|
|
4
|
-
export { useElectronLogger } from "./useElectronLogger"
|
|
5
|
-
export { wrapLoggerForElectron } from "./wrapLoggerForElectron"
|
|
6
|
-
export * from "./types"
|
|
1
|
+
export * from "./types.js"
|
package/src/runtime/electron/{receiveFromRendererOnMain.ts → main/receiveFromRendererOnMain.ts}
RENAMED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ipcMain } from "electron"
|
|
2
2
|
|
|
3
|
-
import { ELECTRON_LOG_TYPE } from "./types.js"
|
|
4
3
|
import type { useElectronLogger } from "./useElectronLogger.js"
|
|
5
4
|
|
|
5
|
+
import { ELECTRON_LOG_TYPE } from "../types.js"
|
|
6
|
+
|
|
6
7
|
export function receiveFromRendererOnMain(logger: ReturnType<typeof useElectronLogger>): void {
|
|
7
8
|
ipcMain.on(ELECTRON_LOG_TYPE.TO_MAIN, (_event, message) => {
|
|
8
9
|
if (typeof message.data === "object" && typeof message.level === "string") {
|
|
@@ -2,12 +2,12 @@ import { keys } from "@alanscodelog/utils/keys"
|
|
|
2
2
|
import type { PublicRuntimeConfig } from "@nuxt/schema"
|
|
3
3
|
import { app, type BrowserWindow } from "electron"
|
|
4
4
|
import path from "node:path"
|
|
5
|
-
import { type Logger
|
|
5
|
+
import pino, { type Logger } from "pino"
|
|
6
6
|
|
|
7
7
|
import { receiveFromRendererOnMain } from "./receiveFromRendererOnMain.js"
|
|
8
|
-
import { ELECTRON_LOG_TYPE } from "./types.js"
|
|
9
8
|
|
|
10
|
-
import { getBaseOptions } from "
|
|
9
|
+
import { getBaseOptions } from "../../helpers/getBaseOptions.js"
|
|
10
|
+
import { ELECTRON_LOG_TYPE } from "../types.js"
|
|
11
11
|
|
|
12
12
|
declare const globalThis: any
|
|
13
13
|
globalThis.__bundlerPathsOverrides = {
|
|
@@ -6,11 +6,11 @@ export function wrapLoggerForElectron<T extends ReturnType<typeof useElectronLog
|
|
|
6
6
|
logger: T,
|
|
7
7
|
prefix: string = "main:"
|
|
8
8
|
): T {
|
|
9
|
-
const res = {}
|
|
10
|
-
for (const key of Object.keys(logger)) {
|
|
9
|
+
const res = {} as Record<keyof T, unknown>
|
|
10
|
+
for (const key of Object.keys(logger) as (keyof T)[]) {
|
|
11
11
|
res[key] = (...args: any[]) => {
|
|
12
|
-
logger[key]({ ...args[0], ns: prefix + args[0].ns }, ...args.slice(1))
|
|
12
|
+
(logger[key] as (...args: any[]) => void)({ ...args[0], ns: prefix + args[0].ns }, ...args.slice(1))
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
return res
|
|
15
|
+
return res as T
|
|
16
16
|
}
|
package/src/runtime/electron/{createElectronLoggerApi.ts → preload/createElectronLoggerApi.ts}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ipcRenderer as IpcRenderer } from "electron"
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import type { Levels } from "../types.js"
|
|
3
|
+
import type { Levels } from "../../types.js"
|
|
4
|
+
import { ELECTRON_LOG_TYPE } from "../types.js"
|
|
6
5
|
|
|
7
6
|
export type ElectronLoggerApi = {
|
|
8
7
|
log: (level: Levels, data: any) => void
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createElectronLoggerApi, type ElectronLoggerApi } from "./createElectronLoggerApi.js"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RuntimeConfig } from "nuxt/schema"
|
|
2
|
-
import { type Logger
|
|
2
|
+
import pino, { type Logger } from "pino"
|
|
3
3
|
|
|
4
4
|
import { getBaseOptions } from "../helpers/getBaseOptions.js"
|
|
5
5
|
import type { BaseLogger, Levels } from "../types.js"
|
|
@@ -38,7 +38,17 @@ export function createUseLogger(
|
|
|
38
38
|
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger, serverPathResolver)
|
|
39
39
|
let transport: any
|
|
40
40
|
if (import.meta.server) {
|
|
41
|
-
|
|
41
|
+
try {
|
|
42
|
+
transport = pino.transport(transports)
|
|
43
|
+
} catch (e) {
|
|
44
|
+
const missingTarget = /unable to determine transport target for "([^"]+)"/.exec((e as Error)?.message ?? "")?.[1]
|
|
45
|
+
if (import.meta.dev && missingTarget === "pino-pretty") {
|
|
46
|
+
console.warn(`[nuxt-logger] "pino-pretty" could not be resolved, pretty console logs are disabled. Add "pino-pretty" to your app dependencies or set disabledServerTransportTargets: ["pino-pretty"].`)
|
|
47
|
+
transport = pino.transport({ targets: transports.targets.filter(t => (t as any).target !== "pino-pretty") })
|
|
48
|
+
} else {
|
|
49
|
+
throw e
|
|
50
|
+
}
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
53
|
const pinoLogger = pino(
|
|
44
54
|
{
|
|
File without changes
|
/package/dist/runtime/electron/{wrapLoggerForElectron.d.ts → main/wrapLoggerForElectron.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|