From 41845445addf9e8dfd8d01381d3ec2c996b0a69c Mon Sep 17 00:00:00 2001 From: n0ky4 Date: Wed, 25 Sep 2024 20:20:28 -0300 Subject: [PATCH] Add optional startup message config --- README.md | 15 ++++++++------- src/index.ts | 9 ++++++--- src/plugins/startServer.ts | 2 +- src/types/index.ts | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1d686a6..7184bf8 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,14 @@ app.listen(3000) ### Options -| Option | Type | Description | Default | -| ------------------ | --------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------- | -| `showBanner` | `boolean` | Display the banner on the console | `true` | -| `ip` | `boolean` | Display the incoming IP address based on the `X-Forwarded-For` header | `false` | -| `customLogMessage` | `string` | Custom log message to display | `🦊 {now} {level} {duration} {method} {pathname} {status} {message} {ip}` | -| `logFilter` | `object` | Filter the logs based on the level, method, and status | `null` | -| `logFilePath` | `string` | Path to the log file | `./logs/elysia.log` | +| Option | Type | Description | Default | +| ---------------------- | ------------------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------- | +| `showStartupMessage` | `boolean` | Display the startup message | `true` | +| `startupMessageFormat` | `"banner"` \| `"simple"` | Choose the startup message format | `"banner"` | +| `ip` | `boolean` | Display the incoming IP address based on the `X-Forwarded-For` header | `false` | +| `customLogMessage` | `string` | Custom log message to display | `🦊 {now} {level} {duration} {method} {pathname} {status} {message} {ip}` | +| `logFilter` | `object` | Filter the logs based on the level, method, and status | `null` | +| `logFilePath` | `string` | Path to the log file | `./logs/elysia.log` | ### Custom Log Message diff --git a/src/index.ts b/src/index.ts index 4d6a164..6d1ef05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,10 @@ export default function logixlysia(options?: Options): Elysia { return new Elysia({ name: 'Logixlysia' }) - .onStart(ctx => startServer(ctx.server as Server, options)) + .onStart(ctx => { + const showStartupMessage = options?.config?.showStartupMessage ?? true + if (showStartupMessage) startServer(ctx.server as Server, options)} + ) .onRequest(ctx => { ctx.store = { beforeTime: process.hrtime.bigint() } }) @@ -26,6 +29,6 @@ export default function logixlysia(options?: Options): Elysia { }) } -export { createLogger } from './core' -export { handleHttpError } from './core' +export { createLogger, handleHttpError } from './core' export { logToTransports } from './transports' + diff --git a/src/plugins/startServer.ts b/src/plugins/startServer.ts index 582dc42..3724964 100644 --- a/src/plugins/startServer.ts +++ b/src/plugins/startServer.ts @@ -8,7 +8,7 @@ const createBoxText = (text: string, width: number): string => { export default function startServer(config: Server, options?: Options): void { const { hostname, port, protocol } = config - const showBanner = options?.config?.showBanner ?? true + const showBanner = options?.config?.startupMessageFormat !== 'simple' if (showBanner) { const ELYSIA_VERSION = import.meta.require('elysia/package.json').version diff --git a/src/types/index.ts b/src/types/index.ts index 4ddc4bb..ed1891e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -88,7 +88,8 @@ export interface Options { } | null ip?: boolean useColors?: boolean - showBanner?: boolean + showStartupMessage?: boolean + startupMessageFormat?: 'banner' | 'simple' transports?: Transport[] } }