Skip to content

Commit

Permalink
fix: improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
arashsheyda committed Mar 9, 2024
1 parent 26728d5 commit c7752ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/runtime/server/plugins/neo4j.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
import type { NitroApp } from 'nitropack'

import { consola } from 'consola'
import { colors } from 'consola/utils'
import { useDriver } from '../utils/driver'

type NitroAppPlugin = (nitro: NitroApp) => void
Expand All @@ -14,12 +12,5 @@ function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin {
}

export default defineNitroPlugin(async () => {
const driver = useDriver()
if (process.dev) {
const info = await driver.getServerInfo()
consola.box({
title: colors.bold(colors.blue(' Neo4j Server Info ')),
message: JSON.stringify(info, null, 2),
})
}
useDriver()
})
20 changes: 18 additions & 2 deletions src/runtime/server/utils/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,26 @@ export function useDriver() {
if (!_driver) {
try {
_driver = neo4j.driver(config.uri, neo4j.auth.basic(config.auth.username, config.auth.password))
consola.success(`Neo4j driver has been ${colors.green('connected.')}`)
if (process.dev) {
(async () => {
try {
const info = await _driver.getServerInfo()
consola.box({
title: colors.bold(colors.green(' Neo4j connection successful. ')),
message: JSON.stringify(info, null, 2),
})
}
catch (error) {
consola.error('Failed to get server info:', error)
}
})()
}
else {
consola.success(`Neo4j connection ${colors.green('successful.')}`)
}
}
catch (error) {
consola.error('Failed to create driver:', error)
consola.error('Failed to create Neo4j driver:', error)
}
}
return _driver
Expand Down

0 comments on commit c7752ab

Please sign in to comment.