@witchcraft/nuxt-logger 0.0.9 → 0.0.11
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.d.mts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +17 -14
- package/dist/runtime/composables/useLogger.d.ts +1 -1
- package/dist/runtime/helpers/getBaseOptions.js +1 -1
- package/dist/runtime/server/utils/useServerLogger.d.ts +1 -1
- package/dist/runtime/shared/createUseLogger.d.ts +1 -4
- package/dist/runtime/types.d.ts +4 -0
- package/package.json +10 -10
- package/src/module.ts +17 -12
- package/src/runtime/helpers/getBaseOptions.ts +2 -2
- package/src/runtime/shared/createUseLogger.ts +1 -4
- package/src/runtime/types.ts +6 -0
package/dist/module.d.mts
CHANGED
|
@@ -68,6 +68,8 @@ interface ModuleOptions {
|
|
|
68
68
|
})[];
|
|
69
69
|
/** Disable a transport target by it's target name. */
|
|
70
70
|
disabledServerTransportTargets?: string[];
|
|
71
|
+
/** Whether to ensure the log dirs exist (for disabling when using the module in layers) */
|
|
72
|
+
ensureLogDirs?: boolean;
|
|
71
73
|
}
|
|
72
74
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
73
75
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { defu } from 'defu';
|
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
|
-
const module = defineNuxtModule({
|
|
6
|
+
const module$1 = defineNuxtModule({
|
|
7
7
|
meta: {
|
|
8
8
|
name: "logger",
|
|
9
9
|
configKey: "logger"
|
|
@@ -23,7 +23,8 @@ const module = defineNuxtModule({
|
|
|
23
23
|
],
|
|
24
24
|
enableServerRequestLogging: false,
|
|
25
25
|
additionalServerTransportTargets: [],
|
|
26
|
-
disabledServerTransportTargets: []
|
|
26
|
+
disabledServerTransportTargets: [],
|
|
27
|
+
ensureLogDirs: true
|
|
27
28
|
},
|
|
28
29
|
async setup(options, nuxt) {
|
|
29
30
|
const { resolve } = createResolver(import.meta.url);
|
|
@@ -31,17 +32,19 @@ const module = defineNuxtModule({
|
|
|
31
32
|
const maybeAppName = nuxt.options.runtimeConfig.public?.appInfo?.name;
|
|
32
33
|
const appName = options.appName ?? maybeAppName ?? path.basename(await resolvePath("~~", { alias: nuxt.options.alias }));
|
|
33
34
|
options.serverLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias(`~~/logs/${appName}.log`, nuxt.options.alias));
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
await fs.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await fs.
|
|
44
|
-
|
|
35
|
+
if (options.ensureLogDirs) {
|
|
36
|
+
if (process.env.NODE_ENV === "development") {
|
|
37
|
+
if (!await fs.stat(options.devServerLogPath).then(() => true).catch(() => false)) {
|
|
38
|
+
await fs.mkdir(path.dirname(options.devServerLogPath), {
|
|
39
|
+
recursive: true
|
|
40
|
+
});
|
|
41
|
+
await fs.writeFile(options.devServerLogPath, "");
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (!await fs.stat(options.serverLogPath).then(() => true).catch(() => false)) {
|
|
45
|
+
await fs.mkdir(path.dirname(options.serverLogPath), { recursive: true });
|
|
46
|
+
await fs.writeFile(options.serverLogPath, "");
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
nuxt.options.runtimeConfig.public.logger = defu(
|
|
@@ -85,4 +88,4 @@ const module = defineNuxtModule({
|
|
|
85
88
|
}
|
|
86
89
|
});
|
|
87
90
|
|
|
88
|
-
export { module as default };
|
|
91
|
+
export { module$1 as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const useLogger: ({ redirectTo, redirectAll }?: {
|
|
2
2
|
redirectTo?: "electron";
|
|
3
3
|
redirectAll?: boolean | ((level: keyof import("pino").Logger, data: any) => boolean);
|
|
4
|
-
}) => import("../
|
|
4
|
+
}) => import("../types.js").BaseLogger;
|
|
@@ -40,7 +40,7 @@ export function getBaseOptions(config, serverPathResolver) {
|
|
|
40
40
|
const maybeElectronLogLevel = import.meta.client ? window.electron?.meta?.env?.LOG_LEVEL : void 0;
|
|
41
41
|
const maybeElectronLogWriteLevel = import.meta.client ? window.electron?.meta?.env?.LOG_WRITE_LEVEL : void 0;
|
|
42
42
|
const writeLevel = maybeElectronLogWriteLevel ?? maybeElectronLogLevel ?? process.env.LOG_WRITE_LEVEL ?? process.env.LOG_LEVEL ?? (import.meta.dev ? "debug" : void 0) ?? "warn";
|
|
43
|
-
const logLevel =
|
|
43
|
+
const logLevel = maybeElectronLogLevel ?? process.env.LOG_LEVEL ?? (import.meta.dev ? "debug" : void 0) ?? "info";
|
|
44
44
|
const processedAdditionalServerTransportTargets = [];
|
|
45
45
|
const thisContexts = [
|
|
46
46
|
...isElectronClient ? ["electron-client"] : [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const useServerLogger: ({ redirectTo, redirectAll }?: {
|
|
2
2
|
redirectTo?: "electron";
|
|
3
3
|
redirectAll?: boolean | ((level: keyof import("pino").Logger, data: any) => boolean);
|
|
4
|
-
}) => import("../../
|
|
4
|
+
}) => import("../../types.js").BaseLogger;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { RuntimeConfig } from "nuxt/schema";
|
|
2
2
|
import { type Logger } from "pino";
|
|
3
|
-
import type {
|
|
4
|
-
export type BaseLogger = Record<Levels, ((data: any) => void)> & {
|
|
5
|
-
flush: Logger["flush"];
|
|
6
|
-
};
|
|
3
|
+
import type { BaseLogger } from "../types.js";
|
|
7
4
|
/**
|
|
8
5
|
* This exists to allow creating useLogger both on the client and the server since for the module to work on the server we must import from `#imports` and have the module transpile the files, but this is not neccesary from the composable.
|
|
9
6
|
*
|
package/dist/runtime/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-logger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Nuxt module for logging.",
|
|
5
5
|
"repository": "witchcraftjs/nuxt-logger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,28 +32,28 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@alanscodelog/tsconfigs": "^6.2.0",
|
|
34
34
|
"@alanscodelog/utils": "^6.0.1",
|
|
35
|
-
"@nuxt/kit": "^4.
|
|
35
|
+
"@nuxt/kit": "^4.3.1",
|
|
36
36
|
"defu": "latest",
|
|
37
37
|
"pino": "^9.9.0",
|
|
38
38
|
"pino-pretty": "^11.3.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@alanscodelog/eslint-config": "^6.3.
|
|
42
|
-
"@alanscodelog/semantic-release-config": "^6.0.
|
|
43
|
-
"@nuxt/eslint-config": "^1.
|
|
41
|
+
"@alanscodelog/eslint-config": "^6.3.1",
|
|
42
|
+
"@alanscodelog/semantic-release-config": "^6.0.2",
|
|
43
|
+
"@nuxt/eslint-config": "^1.15.2",
|
|
44
44
|
"@nuxt/module-builder": "^1.0.2",
|
|
45
|
-
"@nuxt/schema": "^4.
|
|
45
|
+
"@nuxt/schema": "^4.3.1",
|
|
46
46
|
"@nuxt/test-utils": "^3.19.2",
|
|
47
47
|
"@types/node": "latest",
|
|
48
48
|
"changelogen": "^0.6.2",
|
|
49
49
|
"electron": "^34.5.8",
|
|
50
50
|
"eslint": "^9.34.0",
|
|
51
51
|
"husky": "^9.1.7",
|
|
52
|
-
"nuxt": "^4.
|
|
53
|
-
"semantic-release": "^
|
|
54
|
-
"typescript": "^5.9.
|
|
52
|
+
"nuxt": "^4.2.1",
|
|
53
|
+
"semantic-release": "^25.0.3",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
55
|
"vitest": "^3.2.4",
|
|
56
|
-
"vue-tsc": "^
|
|
56
|
+
"vue-tsc": "^3.2.5"
|
|
57
57
|
},
|
|
58
58
|
"release": {
|
|
59
59
|
"extends": [
|
package/src/module.ts
CHANGED
|
@@ -81,6 +81,8 @@ export interface ModuleOptions {
|
|
|
81
81
|
})[]
|
|
82
82
|
/** Disable a transport target by it's target name. */
|
|
83
83
|
disabledServerTransportTargets?: string[]
|
|
84
|
+
/** Whether to ensure the log dirs exist (for disabling when using the module in layers) */
|
|
85
|
+
ensureLogDirs?: boolean
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
export default defineNuxtModule<ModuleOptions>({
|
|
@@ -103,7 +105,8 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
103
105
|
] as string[],
|
|
104
106
|
enableServerRequestLogging: false,
|
|
105
107
|
additionalServerTransportTargets: [],
|
|
106
|
-
disabledServerTransportTargets: []
|
|
108
|
+
disabledServerTransportTargets: [],
|
|
109
|
+
ensureLogDirs: true
|
|
107
110
|
},
|
|
108
111
|
async setup(options, nuxt) {
|
|
109
112
|
const { resolve } = createResolver(import.meta.url)
|
|
@@ -111,17 +114,19 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
111
114
|
const maybeAppName = (nuxt.options.runtimeConfig.public as any)?.appInfo?.name
|
|
112
115
|
const appName = options.appName ?? maybeAppName ?? path.basename(await resolvePath("~~", { alias: nuxt.options.alias }))
|
|
113
116
|
options.serverLogPath ??= path.relative(nuxt.options.rootDir, resolveAlias(`~~/logs/${appName}.log`, nuxt.options.alias))
|
|
114
|
-
if (
|
|
115
|
-
if (
|
|
116
|
-
await fs.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await fs.
|
|
124
|
-
|
|
117
|
+
if (options.ensureLogDirs) {
|
|
118
|
+
if (process.env.NODE_ENV === "development") {
|
|
119
|
+
if (!await fs.stat(options.devServerLogPath).then(() => true).catch(() => false)) {
|
|
120
|
+
await fs.mkdir(path.dirname(options.devServerLogPath), {
|
|
121
|
+
recursive: true
|
|
122
|
+
})
|
|
123
|
+
await fs.writeFile(options.devServerLogPath, "")
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
if (!await fs.stat(options.serverLogPath).then(() => true).catch(() => false)) {
|
|
127
|
+
await fs.mkdir(path.dirname(options.serverLogPath), { recursive: true })
|
|
128
|
+
await fs.writeFile(options.serverLogPath, "")
|
|
129
|
+
}
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
|
|
@@ -71,10 +71,10 @@ export function getBaseOptions(
|
|
|
71
71
|
?? (import.meta.dev ? "debug" : undefined)
|
|
72
72
|
?? "warn"
|
|
73
73
|
const logLevel: (typeof validLevels)[number]
|
|
74
|
-
=
|
|
74
|
+
= maybeElectronLogLevel
|
|
75
75
|
?? process.env.LOG_LEVEL as any
|
|
76
76
|
?? (import.meta.dev ? "debug" : undefined)
|
|
77
|
-
?? "
|
|
77
|
+
?? "info"
|
|
78
78
|
|
|
79
79
|
const processedAdditionalServerTransportTargets = []
|
|
80
80
|
const thisContexts = [
|
|
@@ -2,11 +2,8 @@ import type { RuntimeConfig } from "nuxt/schema"
|
|
|
2
2
|
import { type Logger, pino } from "pino"
|
|
3
3
|
|
|
4
4
|
import { getBaseOptions } from "../helpers/getBaseOptions.js"
|
|
5
|
-
import type { Levels } from "../types.js"
|
|
5
|
+
import type { BaseLogger, Levels } from "../types.js"
|
|
6
6
|
|
|
7
|
-
export type BaseLogger = Record<Levels, ((data: any) => void)> & {
|
|
8
|
-
flush: Logger["flush"]
|
|
9
|
-
}
|
|
10
7
|
const logger: BaseLogger = {} as any
|
|
11
8
|
|
|
12
9
|
/**
|