Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional startup message config #66

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion example/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const app = new Elysia({
.use(
logixlysia({
config: {
showBanner: false,
showStartupMessage: true,
startupMessageFormat: 'simple',
logFilePath: './logs/example.log',
ip: true,
customLogFormat:
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[]
}
}