@witchcraft/nuxt-logger 0.0.3 → 0.0.5
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/dist/module.json +1 -1
- package/dist/runtime/helpers/getBaseOptions.d.ts +1 -1
- package/dist/runtime/helpers/getBaseOptions.js +4 -4
- package/dist/runtime/server/utils/useServerLogger.js +2 -1
- package/dist/runtime/shared/createUseLogger.d.ts +1 -1
- package/dist/runtime/shared/createUseLogger.js +2 -2
- package/package.json +1 -1
- package/src/runtime/helpers/getBaseOptions.ts +5 -4
- package/src/runtime/server/utils/useServerLogger.ts +3 -1
- package/src/runtime/shared/createUseLogger.ts +3 -2
package/dist/module.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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;
|
|
@@ -3,7 +3,6 @@ import { keys } from "@alanscodelog/utils/keys";
|
|
|
3
3
|
import { readable } from "@alanscodelog/utils/readable";
|
|
4
4
|
import { set } from "@alanscodelog/utils/set";
|
|
5
5
|
import { walk } from "@alanscodelog/utils/walk";
|
|
6
|
-
import path from "node:path";
|
|
7
6
|
import { pino } from "pino";
|
|
8
7
|
const levels = {
|
|
9
8
|
values: {
|
|
@@ -24,7 +23,7 @@ const levels = {
|
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
25
|
const isElectronClient = typeof window !== "undefined" && "electron" in window && window.electron;
|
|
27
|
-
export function getBaseOptions(config) {
|
|
26
|
+
export function getBaseOptions(config, serverPathResolver) {
|
|
28
27
|
if (isElectronClient) {
|
|
29
28
|
delete config.logPath;
|
|
30
29
|
}
|
|
@@ -65,10 +64,11 @@ export function getBaseOptions(config) {
|
|
|
65
64
|
}
|
|
66
65
|
delete clone._loadFromEnv;
|
|
67
66
|
}
|
|
67
|
+
const resolvedLogPath = serverPathResolver?.(logPath) ?? logPath;
|
|
68
68
|
return {
|
|
69
69
|
debug: {
|
|
70
70
|
logPath,
|
|
71
|
-
resolvedLogPath
|
|
71
|
+
resolvedLogPath,
|
|
72
72
|
writeLevel,
|
|
73
73
|
logLevel
|
|
74
74
|
},
|
|
@@ -102,7 +102,7 @@ export function getBaseOptions(config) {
|
|
|
102
102
|
level: writeLevel,
|
|
103
103
|
target: "pino/file",
|
|
104
104
|
options: {
|
|
105
|
-
destination:
|
|
105
|
+
destination: resolvedLogPath,
|
|
106
106
|
mkdir: true
|
|
107
107
|
}
|
|
108
108
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { useRuntimeConfig } from "#imports";
|
|
2
3
|
import { createUseLogger } from "../../shared/createUseLogger.js";
|
|
3
|
-
export const useServerLogger = createUseLogger(useRuntimeConfig);
|
|
4
|
+
export const useServerLogger = createUseLogger(useRuntimeConfig, path.resolve);
|
|
@@ -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
|
@@ -4,7 +4,6 @@ import { readable } from "@alanscodelog/utils/readable"
|
|
|
4
4
|
import { set } from "@alanscodelog/utils/set"
|
|
5
5
|
import { walk } from "@alanscodelog/utils/walk"
|
|
6
6
|
import type { PublicRuntimeConfig } from "@nuxt/schema"
|
|
7
|
-
import path from "node:path"
|
|
8
7
|
import type { LoggerOptions, TransportMultiOptions } from "pino"
|
|
9
8
|
import { pino } from "pino"
|
|
10
9
|
|
|
@@ -32,7 +31,8 @@ const levels = {
|
|
|
32
31
|
const isElectronClient = (typeof window !== "undefined" && "electron" in window && window.electron)
|
|
33
32
|
|
|
34
33
|
export function getBaseOptions(
|
|
35
|
-
config: PublicRuntimeConfig["logger"]
|
|
34
|
+
config: PublicRuntimeConfig["logger"],
|
|
35
|
+
serverPathResolver?: (path: string) => string
|
|
36
36
|
): {
|
|
37
37
|
opts: LoggerOptions
|
|
38
38
|
browserOpts: LoggerOptions
|
|
@@ -102,10 +102,11 @@ export function getBaseOptions(
|
|
|
102
102
|
delete (clone as any)._loadFromEnv
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
const resolvedLogPath = serverPathResolver?.(logPath) ?? logPath
|
|
105
106
|
return {
|
|
106
107
|
debug: {
|
|
107
108
|
logPath,
|
|
108
|
-
resolvedLogPath
|
|
109
|
+
resolvedLogPath,
|
|
109
110
|
writeLevel,
|
|
110
111
|
logLevel
|
|
111
112
|
},
|
|
@@ -141,7 +142,7 @@ export function getBaseOptions(
|
|
|
141
142
|
level: writeLevel,
|
|
142
143
|
target: "pino/file",
|
|
143
144
|
options: {
|
|
144
|
-
destination:
|
|
145
|
+
destination: resolvedLogPath,
|
|
145
146
|
mkdir: true
|
|
146
147
|
}
|
|
147
148
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
|
|
1
3
|
import { useRuntimeConfig } from "#imports"
|
|
2
4
|
|
|
3
5
|
import { createUseLogger } from "../../shared/createUseLogger.js"
|
|
4
6
|
|
|
5
|
-
export const useServerLogger = createUseLogger(useRuntimeConfig)
|
|
7
|
+
export const useServerLogger = createUseLogger(useRuntimeConfig, path.resolve)
|
|
@@ -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)
|