一键导入
logixlysia
Coding guidelines, API usage, and configuration standards for using the Logixlysia logger plugin in Elysia.js applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Coding guidelines, API usage, and configuration standards for using the Logixlysia logger plugin in Elysia.js applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | logixlysia |
| description | Coding guidelines, API usage, and configuration standards for using the Logixlysia logger plugin in Elysia.js applications. |
Logixlysia is an opinionated, high-performance logger plugin for Elysia.js applications. It provides request-scoped logging, structured logging via Pino, context propagation, automatic PII redaction, and WebSocket tracing.
To register Logixlysia in an Elysia application:
import { Elysia } from 'elysia'
import { logixlysia } from 'logixlysia'
const app = new Elysia()
.use(logixlysia()) // Register with default options
.get('/', () => 'Hello Elysia')
.listen(3000)
Logixlysia derives a log object (of type RequestScopedLogger) onto the Elysia request context. Always prefer using this request-scoped logger inside route handlers instead of importing global loggers, as it tracks timing, request paths, and request-specific context.
app.get('/user/:id', ({ params, log }) => {
log.info('Fetching user', { userId: params.id })
return { success: true }
})
You can append custom fields to the current request's log using log.mergeContext(). These fields are automatically displayed as an easy-to-read tree structure underneath the main HTTP log line.
app.get('/order/checkout', ({ log }) => {
log.mergeContext({ cartId: 'cart-123', promoUsed: true })
log.info('Cart validated') // Logs with cartId and promoUsed context
return { status: 'processed' }
})
Use the options object to configure presets, logging thresholds, filters, and formats:
app.use(
logixlysia({
preset: 'prod', // Options: 'dev' | 'prod' | 'json'
config: {
showStartupMessage: true,
startupMessageFormat: 'banner', // 'simple' | 'banner'
ip: true, // Log client IP address
logQueryParams: true, // Log URL query parameters
// Request tracing and propagation
requestId: {
enabled: true,
header: 'X-Request-Id', // Default tracing header
},
// Custom formatting and coloring
useColors: true,
slowThreshold: 500, // Duration below this logs as green
verySlowThreshold: 1000, // Duration at or above this logs as red
showContextTree: true, // Show mergeContext properties as tree branches
contextDepth: 2, // How deep to expand nested objects in the tree
// Auto-redaction of PII (emails, JWTs, card numbers)
autoRedact: true,
// AsyncLocalStorage integration
useAsyncLocalStorage: true,
}
})
)
If useAsyncLocalStorage is enabled in configuration, you can retrieve the request-scoped logger anywhere in your codebase (e.g. inside database services, controllers, or helper files) using useLogger().
import { useLogger } from 'logixlysia'
export const fetchFromDatabase = async (userId: string) => {
const log = useLogger() // Fetches the logger for the current async execution context
log?.info('Querying database', { userId })
// Database logic...
}
To enable request-scoped tracing and logging in WebSockets, wrap your WebSocket handler hooks using wrapWs. This allows logging lifecycle events like connections, message exchanges, and closures.
import { Elysia } from 'elysia'
import { logixlysia } from 'logixlysia'
const logger = logixlysia()
const app = new Elysia()
.use(logger)
.ws('/ws', logger.wrapWs({
open(ws) {
ws.data.log.info('WebSocket connection opened')
},
message(ws, message) {
ws.data.log.info('Message received', { payload: message })
},
close(ws, code, reason) {
ws.data.log.info('WebSocket closed', { code, reason })
}
}))
When writing or modifying code relating to Logixlysia:
any for context arguments. Leverage the RequestScopedLogger and LogixlysiaContext interfaces.Record<string, never>. Use a dedicated empty interface like:
export interface EmptyElysiaSlot {
readonly __logixlysiaEmpty?: never
}
to prevent context properties from narrowing to never.onStop lifecycle).