Skip to content

Commit

Permalink
Add optional startup message config
Browse files Browse the repository at this point in the history
  • Loading branch information
n0ky4 committed Sep 25, 2024
1 parent ea27836 commit 4184544
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
})
Expand All @@ -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'

2 changes: 1 addition & 1 deletion src/plugins/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export interface Options {
} | null
ip?: boolean
useColors?: boolean
showBanner?: boolean
showStartupMessage?: boolean
startupMessageFormat?: 'banner' | 'simple'
transports?: Transport[]
}
}

0 comments on commit 4184544

Please sign in to comment.