@witchcraft/nuxt-logger 0.0.8 → 0.0.10
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 +2 -2
- package/dist/module.mjs +15 -12
- package/package.json +1 -1
- package/src/module.ts +17 -12
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
|
@@ -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(
|
package/package.json
CHANGED
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
|
|