Skip to content

Commit b394581

Browse files
committed
chore: improve logging
1 parent 7de9c86 commit b394581

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

src/features.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export { setupKV } from './features/kv'
1212
export { setupOpenAPI } from './features/openapi'
1313

1414
export function logWhenReady(nuxt: Nuxt, message: string, type: 'info' | 'warn' | 'error' = 'info') {
15-
nuxt.hooks.hookOnce('modules:done', () => {
16-
log[type](message)
17-
})
15+
if (nuxt.options.dev) {
16+
nuxt.hooks.hookOnce('modules:done', () => {
17+
log[type](message)
18+
})
19+
}
1820
}
1921

2022
export interface HubConfig {

src/features/ai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function setupAI(nuxt: Nuxt, hub: HubConfig) {
5555
addServerScanDir(resolve('../runtime/ai/server'))
5656
addServerImportsDir(resolve('../runtime/ai/server/utils'))
5757

58-
logWhenReady(nuxt, `\`hubAI()\` configured with ${providerName}`)
58+
logWhenReady(nuxt, `\`hubAI()\` configured with \`${providerName}\``)
5959
}
6060

6161
export async function setupProductionAI(nitro: Nitro, hub: HubConfig) {
@@ -118,6 +118,7 @@ export async function setupProductionAI(nitro: Nitro, hub: HubConfig) {
118118
}
119119

120120
if (hub.ai) {
121-
log.info(`Using zero-config \`${hub.ai}\` AI provider`)
121+
const providerName = hub.ai === 'vercel' ? 'Vercel AI Gateway' : 'Workers AI Provider'
122+
log.info(`\`hubAI()\` configured with \`${providerName}\``)
122123
}
123124
}

src/features/blob.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export function setupBlob(nuxt: Nuxt, hub: HubConfig) {
3131
nuxt.options.runtimeConfig.public.hub.blobProvider = 'vercel-blob'
3232
}
3333

34-
const driver = nuxt.options.dev ? nuxt.options.nitro.devStorage.blob.driver : nuxt.options.nitro.storage?.blob?.driver
35-
36-
logWhenReady(nuxt, `\`hubBlob()\` configured with \`${driver}\` driver`)
34+
logWhenReady(nuxt, `\`hubBlob()\` configured with \`${nuxt.options.nitro.devStorage.blob.driver}\` driver`)
3735
}
3836

3937
export async function setupProductionBlob(nitro: Nitro, _hub: HubConfig) {
@@ -42,7 +40,7 @@ export async function setupProductionBlob(nitro: Nitro, _hub: HubConfig) {
4240

4341
// Only configure if blob driver is not already set
4442
if (nitro.options.storage?.blob?.driver) {
45-
log.info(`Using user-configured \`${nitro.options.storage.blob.driver}\` blob driver`)
43+
log.info(`\`hubBlob()\` configured with \`${nitro.options.storage.blob.driver}\` driver (defined in \`nuxt.config.ts\`)`)
4644
return
4745
}
4846
let kvConfig: NitroOptions['storage']['blob']
@@ -55,7 +53,7 @@ export async function setupProductionBlob(nitro: Nitro, _hub: HubConfig) {
5553
driver: 'vercel-blob',
5654
access: 'public'
5755
}
58-
log.warn('Files stored in Vercel Blob are always public. Specify a different storage driver if storing sensitive files.')
56+
log.warn('Files stored in Vercel Blob are public. Manually configure a different storage driver if storing sensitive files.')
5957
break
6058
}
6159

@@ -153,6 +151,6 @@ export async function setupProductionBlob(nitro: Nitro, _hub: HubConfig) {
153151
// set driver
154152
nitro.options.storage ||= {}
155153
nitro.options.storage.blob = defu(nitro.options.storage?.blob, kvConfig)
156-
log.info(`Using zero-config \`${kvConfig.driver}\` blob driver`)
154+
log.info(`\`hubBlob()\` configured with \`${kvConfig.driver}\` driver`)
157155
}
158156
}

src/features/cache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join } from 'pathe'
33
import { defu } from 'defu'
44
import { isWindows } from 'std-env'
55
import { createResolver, addServerScanDir, logger, resolvePath } from '@nuxt/kit'
6+
import { logWhenReady } from '../features'
67

78
import type { Nuxt } from '@nuxt/schema'
89
import type { Nitro, NitroOptions } from 'nitropack'
@@ -21,6 +22,8 @@ export async function setupCache(nuxt: Nuxt, hub: HubConfig) {
2122

2223
// Add Server scanning
2324
addServerScanDir(resolve('../runtime/cache/server'))
25+
26+
logWhenReady(nuxt, `Application cache configured with \`${nuxt.options.nitro.devStorage.cache.driver}\` driver`)
2427
}
2528

2629
export async function setupProductionCache(nitro: Nitro, _hub: HubConfig) {
@@ -71,6 +74,6 @@ export async function setupProductionCache(nitro: Nitro, _hub: HubConfig) {
7174
if (cacheConfig) {
7275
nitro.options.storage ||= {}
7376
nitro.options.storage.cache = defu(nitro.options.storage?.cache, cacheConfig)
74-
log.info(`Using zero-config \`${cacheConfig.driver}\` cache driver`)
77+
log.info(`Application cache configured with \`${nitro.options.storage.cache.driver}\` driver`)
7578
}
7679
}

src/features/database.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function setupDatabase(nuxt: Nuxt, hub: HubConfig) {
7878
if (process.env.POSTGRES_URL || process.env.POSTGRESQL_URL || process.env.DATABASE_URL) {
7979
// Use postgresql if env variable is set
8080
const setEnvVarName = process.env.POSTGRES_URL ? 'POSTGRES_URL' : process.env.POSTGRESQL_URL ? 'POSTGRESQL_URL' : 'DATABASE_URL'
81-
logWhenReady(nuxt, `Using \`PostgreSQL\` during local development using provided \`${setEnvVarName}\``)
81+
logWhenReady(nuxt, `\`hubDatabase()\` configured with \`PostgreSQL\` using provided \`${setEnvVarName}\``)
8282
devDatabaseConfig = {
8383
connector: 'postgresql',
8484
options: {
@@ -87,7 +87,7 @@ export async function setupDatabase(nuxt: Nuxt, hub: HubConfig) {
8787
}
8888
} else {
8989
// Use pglite if env variable not provided
90-
logWhenReady(nuxt, 'Using `PGlite` during local development')
90+
logWhenReady(nuxt, '`hubDatabase()` configured with `PGlite` during local development')
9191
devDatabaseConfig = {
9292
connector: 'pglite',
9393
options: {
@@ -96,7 +96,7 @@ export async function setupDatabase(nuxt: Nuxt, hub: HubConfig) {
9696
}
9797
}
9898
} else if (dialect === 'sqlite') {
99-
logWhenReady(nuxt, 'Using `SQLite` during local development')
99+
logWhenReady(nuxt, '`hubDatabase()` configured with `SQLite` during local development')
100100
devDatabaseConfig = {
101101
connector: 'better-sqlite3',
102102
options: {
@@ -105,7 +105,7 @@ export async function setupDatabase(nuxt: Nuxt, hub: HubConfig) {
105105
}
106106
} else if (dialect === 'mysql') {
107107
if (!nuxt.options.nitro.devDatabase?.db?.connector) {
108-
logWhenReady(nuxt, 'Zero-config `MySQL` database setup during local development is not supported yet. Please manually configure your development database in `nitro.devDatabase.db` in `nuxt.config.ts`. Learn more at https://hub.nuxt.com/docs/features/database.', 'warn')
108+
logWhenReady(nuxt, '`hubDatabase()` configured with `MySQL` during local development is not supported yet. Please manually configure your development database in `nitro.devDatabase.db` in `nuxt.config.ts`. Learn more at https://hub.nuxt.com/docs/features/database.', 'warn')
109109
}
110110
}
111111

@@ -227,7 +227,7 @@ export async function setupProductionDatabase(nitro: Nitro, hub: HubConfig) {
227227

228228
// Only configure if production database connector is not already set
229229
if (nitro.options.database?.db?.connector) {
230-
log.info(`Using user-configured \`${nitro.options.database.db.connector}\` database connector`)
230+
log.info(`\`hubDatabase()\` configured with \`${nitro.options.database.db.connector}\` driver (defined in \`nuxt.config.ts\`)`)
231231
return
232232
}
233233

@@ -363,6 +363,6 @@ export async function setupProductionDatabase(nitro: Nitro, hub: HubConfig) {
363363
// @ts-expect-error temporarily set to empty object
364364
nitro.options.database ||= {}
365365
nitro.options.database.db = defu(nitro.options.database?.db, databaseConfig) as any
366-
log.info(`Using zero-config \`${databaseConfig.connector}\` database connector`)
366+
log.info(`\`hubDatabase()\` configured with \`${databaseConfig.connector}\` driver`)
367367
}
368368
}

src/features/kv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function setupProductionKV(nitro: Nitro, _hub: HubConfig) {
3434

3535
// Only configure if KV driver is not already set
3636
if (nitro.options.storage?.kv?.driver) {
37-
log.info(`Using user-configured \`${nitro.options.storage.kv.driver}\` KV driver`)
37+
log.info(`\`hubKV()\` configured with \`${nitro.options.storage.kv.driver}\` driver (defined in \`nuxt.config.ts\`)`)
3838
return
3939
}
4040

@@ -93,6 +93,6 @@ export async function setupProductionKV(nitro: Nitro, _hub: HubConfig) {
9393
// set driver
9494
nitro.options.storage ||= {}
9595
nitro.options.storage.kv = defu(nitro.options.storage?.kv, kvConfig)
96-
log.info(`Using zero-config \`${kvConfig.driver}\` KV driver`)
96+
log.info(`\`hubKV()\` configured with \`${kvConfig.driver}\` driver`)
9797
}
9898
}

src/utils/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join } from 'pathe'
33
import type { Nuxt } from '@nuxt/schema'
44
import type { HubConfig } from '../features'
55

6+
import { setupProductionAI } from '../features/ai'
67
import { setupProductionBlob } from '../features/blob'
78
import { setupProductionCache } from '../features/cache'
89
import { setupProductionDatabase } from '../features/database'
@@ -37,6 +38,7 @@ export function addBuildHooks(nuxt: Nuxt, hub: HubConfig) {
3738
}
3839

3940
await Promise.all([
41+
hub.ai && await setupProductionAI(nitro, hub),
4042
hub.blob && await setupProductionBlob(nitro, hub),
4143
hub.cache && await setupProductionCache(nitro, hub),
4244
hub.database && await setupProductionDatabase(nitro, hub),

0 commit comments

Comments
 (0)