@witchcraft/nuxt-logger 0.0.2 → 0.0.4
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 +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -3
- package/dist/runtime/helpers/getBaseOptions.d.ts +2 -1
- package/dist/runtime/helpers/getBaseOptions.js +5 -2
- package/dist/runtime/server/utils/useServerLogger.js +1 -2
- package/dist/runtime/shared/createUseLogger.d.ts +1 -1
- package/dist/runtime/shared/createUseLogger.js +2 -2
- package/package.json +2 -2
- package/src/module.ts +3 -2
- package/src/runtime/helpers/getBaseOptions.ts +7 -2
- package/src/runtime/server/utils/useServerLogger.ts +2 -1
- package/src/runtime/shared/createUseLogger.ts +3 -2
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ Also redacts the `redact` key, but only in production, so you can put anything s
|
|
|
46
46
|
The electron logger requires a bit of setup since electron's main cannot be passed the runtime config normally.
|
|
47
47
|
|
|
48
48
|
This assumes the usage of
|
|
49
|
-
[@witchcraft/nuxt-electron](
|
|
49
|
+
[@witchcraft/nuxt-electron](https://github.com/witchcraftjs/nuxt-electron) since it can handle this among other issues.
|
|
50
50
|
|
|
51
51
|
There is a full example in the [@witchcraft/nuxt-electron playground](TODO).
|
|
52
52
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, resolvePath, addImportsDir, addServerImportsDir, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, resolveAlias, resolvePath, addImportsDir, addServerImportsDir, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
@@ -27,10 +27,10 @@ const module = defineNuxtModule({
|
|
|
27
27
|
},
|
|
28
28
|
async setup(options, nuxt) {
|
|
29
29
|
const { resolve } = createResolver(import.meta.url);
|
|
30
|
-
options.devServerLogPath ??=
|
|
30
|
+
options.devServerLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias("~~/logs/server.log", nuxt.options.alias));
|
|
31
31
|
const maybeAppName = nuxt.options.runtimeConfig.public?.appInfo?.name;
|
|
32
32
|
const appName = options.appName ?? maybeAppName ?? path.basename(await resolvePath("~~", { alias: nuxt.options.alias }));
|
|
33
|
-
options.serverLogPath ??=
|
|
33
|
+
options.serverLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias(`~~/logs/${appName}.log`, nuxt.options.alias));
|
|
34
34
|
if (process.env.NODE_ENV === "development") {
|
|
35
35
|
if (!await fs.stat(options.devServerLogPath).then(() => true).catch(() => false)) {
|
|
36
36
|
await fs.mkdir(path.dirname(options.devServerLogPath), {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { PublicRuntimeConfig } from "@nuxt/schema";
|
|
2
2
|
import type { LoggerOptions, TransportMultiOptions } from "pino";
|
|
3
|
-
export declare function getBaseOptions(config: PublicRuntimeConfig["logger"]): {
|
|
3
|
+
export declare function getBaseOptions(config: PublicRuntimeConfig["logger"], serverPathResolver?: (path: string) => string): {
|
|
4
4
|
opts: LoggerOptions;
|
|
5
5
|
browserOpts: LoggerOptions;
|
|
6
6
|
transports: TransportMultiOptions;
|
|
7
7
|
debug: {
|
|
8
8
|
logPath: string;
|
|
9
|
+
resolvedLogPath: string;
|
|
9
10
|
writeLevel: string;
|
|
10
11
|
logLevel: string;
|
|
11
12
|
};
|
|
@@ -23,7 +23,7 @@ const levels = {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
const isElectronClient = typeof window !== "undefined" && "electron" in window && window.electron;
|
|
26
|
-
export function getBaseOptions(config) {
|
|
26
|
+
export function getBaseOptions(config, serverPathResolver) {
|
|
27
27
|
if (isElectronClient) {
|
|
28
28
|
delete config.logPath;
|
|
29
29
|
}
|
|
@@ -64,9 +64,11 @@ export function getBaseOptions(config) {
|
|
|
64
64
|
}
|
|
65
65
|
delete clone._loadFromEnv;
|
|
66
66
|
}
|
|
67
|
+
const resolvedLogPath = serverPathResolver?.(logPath) ?? logPath;
|
|
67
68
|
return {
|
|
68
69
|
debug: {
|
|
69
70
|
logPath,
|
|
71
|
+
resolvedLogPath,
|
|
70
72
|
writeLevel,
|
|
71
73
|
logLevel
|
|
72
74
|
},
|
|
@@ -77,6 +79,7 @@ export function getBaseOptions(config) {
|
|
|
77
79
|
formatters: {
|
|
78
80
|
bindings: () => ({})
|
|
79
81
|
},
|
|
82
|
+
// @ts-expect-error https://github.com/pinojs/pino/issues/2260
|
|
80
83
|
timestamp: pino.stdTimeFunctions.isoTime
|
|
81
84
|
},
|
|
82
85
|
browserOpts: {
|
|
@@ -99,7 +102,7 @@ export function getBaseOptions(config) {
|
|
|
99
102
|
level: writeLevel,
|
|
100
103
|
target: "pino/file",
|
|
101
104
|
options: {
|
|
102
|
-
destination:
|
|
105
|
+
destination: resolvedLogPath,
|
|
103
106
|
mkdir: true
|
|
104
107
|
}
|
|
105
108
|
},
|
|
@@ -9,7 +9,7 @@ export type BaseLogger = Record<Levels, ((data: any) => void)> & {
|
|
|
9
9
|
*
|
|
10
10
|
* So they both create useLogger by passing in useRuntimeConfig how they can.
|
|
11
11
|
*/
|
|
12
|
-
export declare function createUseLogger(rc: () => RuntimeConfig): ({ redirectTo, redirectAll }?: {
|
|
12
|
+
export declare function createUseLogger(rc: () => RuntimeConfig, serverPathResolver?: (path: string) => string): ({ redirectTo, redirectAll }?: {
|
|
13
13
|
redirectTo?: "electron";
|
|
14
14
|
/**
|
|
15
15
|
* Prefixes all messages not coming from main with `renderer:` so that they will be forwarded.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pino } from "pino";
|
|
2
2
|
import { getBaseOptions } from "../helpers/getBaseOptions.js";
|
|
3
3
|
const logger = {};
|
|
4
|
-
export function createUseLogger(rc) {
|
|
4
|
+
export function createUseLogger(rc, serverPathResolver) {
|
|
5
5
|
let initiated = false;
|
|
6
6
|
return function useLogger({
|
|
7
7
|
redirectTo,
|
|
@@ -11,7 +11,7 @@ export function createUseLogger(rc) {
|
|
|
11
11
|
if (!initiated) {
|
|
12
12
|
initiated = true;
|
|
13
13
|
const config = rc().public;
|
|
14
|
-
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger);
|
|
14
|
+
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger, serverPathResolver);
|
|
15
15
|
let transport;
|
|
16
16
|
if (import.meta.server) {
|
|
17
17
|
transport = pino.transport(transports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-logger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Nuxt module for logging.",
|
|
5
5
|
"repository": "witchcraftjs/nuxt-logger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"pino-pretty": "^11.2.2"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@alanscodelog/tsconfigs": "^6.
|
|
44
|
+
"@alanscodelog/tsconfigs": "^6.2.0",
|
|
45
45
|
"@alanscodelog/utils": "^6.0.1",
|
|
46
46
|
"@nuxt/kit": "^4.0.3",
|
|
47
47
|
"defu": "latest",
|
package/src/module.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
addServerImportsDir,
|
|
6
6
|
createResolver,
|
|
7
7
|
defineNuxtModule,
|
|
8
|
+
resolveAlias,
|
|
8
9
|
resolvePath
|
|
9
10
|
} from "@nuxt/kit"
|
|
10
11
|
import { defu } from "defu"
|
|
@@ -106,10 +107,10 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
106
107
|
},
|
|
107
108
|
async setup(options, nuxt) {
|
|
108
109
|
const { resolve } = createResolver(import.meta.url)
|
|
109
|
-
options.devServerLogPath ??=
|
|
110
|
+
options.devServerLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias("~~/logs/server.log", nuxt.options.alias))
|
|
110
111
|
const maybeAppName = (nuxt.options.runtimeConfig.public as any)?.appInfo?.name
|
|
111
112
|
const appName = options.appName ?? maybeAppName ?? path.basename(await resolvePath("~~", { alias: nuxt.options.alias }))
|
|
112
|
-
options.serverLogPath ??=
|
|
113
|
+
options.serverLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias(`~~/logs/${appName}.log`, nuxt.options.alias))
|
|
113
114
|
if (process.env.NODE_ENV === "development") {
|
|
114
115
|
if (!await fs.stat(options.devServerLogPath).then(() => true).catch(() => false)) {
|
|
115
116
|
await fs.mkdir(path.dirname(options.devServerLogPath), {
|
|
@@ -31,13 +31,15 @@ const levels = {
|
|
|
31
31
|
const isElectronClient = (typeof window !== "undefined" && "electron" in window && window.electron)
|
|
32
32
|
|
|
33
33
|
export function getBaseOptions(
|
|
34
|
-
config: PublicRuntimeConfig["logger"]
|
|
34
|
+
config: PublicRuntimeConfig["logger"],
|
|
35
|
+
serverPathResolver?: (path: string) => string
|
|
35
36
|
): {
|
|
36
37
|
opts: LoggerOptions
|
|
37
38
|
browserOpts: LoggerOptions
|
|
38
39
|
transports: TransportMultiOptions
|
|
39
40
|
debug: {
|
|
40
41
|
logPath: string
|
|
42
|
+
resolvedLogPath: string
|
|
41
43
|
writeLevel: string
|
|
42
44
|
logLevel: string
|
|
43
45
|
}
|
|
@@ -100,9 +102,11 @@ export function getBaseOptions(
|
|
|
100
102
|
delete (clone as any)._loadFromEnv
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
const resolvedLogPath = serverPathResolver?.(logPath) ?? logPath
|
|
103
106
|
return {
|
|
104
107
|
debug: {
|
|
105
108
|
logPath,
|
|
109
|
+
resolvedLogPath,
|
|
106
110
|
writeLevel,
|
|
107
111
|
logLevel
|
|
108
112
|
},
|
|
@@ -113,6 +117,7 @@ export function getBaseOptions(
|
|
|
113
117
|
formatters: {
|
|
114
118
|
bindings: () => ({})
|
|
115
119
|
},
|
|
120
|
+
// @ts-expect-error https://github.com/pinojs/pino/issues/2260
|
|
116
121
|
timestamp: pino.stdTimeFunctions.isoTime
|
|
117
122
|
},
|
|
118
123
|
browserOpts: {
|
|
@@ -137,7 +142,7 @@ export function getBaseOptions(
|
|
|
137
142
|
level: writeLevel,
|
|
138
143
|
target: "pino/file",
|
|
139
144
|
options: {
|
|
140
|
-
destination:
|
|
145
|
+
destination: resolvedLogPath,
|
|
141
146
|
mkdir: true
|
|
142
147
|
}
|
|
143
148
|
},
|
|
@@ -15,7 +15,8 @@ const logger: BaseLogger = {} as any
|
|
|
15
15
|
* So they both create useLogger by passing in useRuntimeConfig how they can.
|
|
16
16
|
*/
|
|
17
17
|
export function createUseLogger(
|
|
18
|
-
rc: () => RuntimeConfig
|
|
18
|
+
rc: () => RuntimeConfig,
|
|
19
|
+
serverPathResolver?: (path: string) => string
|
|
19
20
|
) {
|
|
20
21
|
let initiated = false
|
|
21
22
|
return function useLogger({
|
|
@@ -37,7 +38,7 @@ export function createUseLogger(
|
|
|
37
38
|
initiated = true
|
|
38
39
|
|
|
39
40
|
const config = rc().public
|
|
40
|
-
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger)
|
|
41
|
+
const { opts, transports, browserOpts, debug } = getBaseOptions(config.logger, serverPathResolver)
|
|
41
42
|
let transport: any
|
|
42
43
|
if (import.meta.server) {
|
|
43
44
|
transport = pino.transport(transports)
|