Skip to content
Logixlysia
Esc
↑↓navigate↵open⌘Jpreview
On this page

Migrating from evlog

Map evlog wide events to Logixlysia request context and access logs

Plugin setup

evlog

import { Elysia } from 'elysia'
import { evlog } from 'evlog/elysia'

new Elysia().use(evlog({ drain: myDrain }))

Logixlysia

import { Elysia } from 'elysia'
import logixlysia from 'logixlysia'
import { createAxiomTransport } from 'logixlysia/axiom'

new Elysia().use(
  logixlysia({
    preset: 'prod',
    config: { transports: [createAxiomTransport()] }
  })
)

preset: 'prod' on its own writes JSON lines to the console and sends nothing anywhere else. Add the adapter that matches your drain (the table below) to keep remote delivery. The example uses Axiom, whose adapter reads AXIOM_API_KEY and AXIOM_DATASET and throws at startup without them.

Context accumulation

log is always on the handler context; outside a handler, store.logger takes the request explicitly. useLogger() needs useAsyncLocalStorage: true in a request and works without it inside runJob. Outside both it is a no-op, where evlog’s useLogger() throws.

evlog Logixlysia, in a handler Logixlysia, with a request in hand
log.set({ userId: 'x' }) ({ log }) => log.mergeContext({ userId: 'x' }) store.logger.mergeContext(request, { userId: 'x' })
log.set({ cart: { total: 99 } }) ({ log }) => log.mergeContext({ cart: { total: 99 } }) store.logger.mergeContext(request, { cart: { total: 99 } })
useLogger() useLogger() from logixlysia useLogger() from logixlysia

Emitting the request log

evlog’s Elysia plugin emits the request’s event by itself when the request ends. log.emit() is for a logger you created yourself, in a script or a worker:

log.emit({ status: 200 })

Logixlysia emits the access log automatically once Elysia has produced the response. A line you log yourself does not replace it:

store.logger.info(request, 'handled manually')

AI metrics

evlog — wrap the model with createAIMiddleware(log) from evlog/ai.

Logixlysia

import { gateway, streamText, wrapLanguageModel } from 'ai'
import { aiMiddleware } from 'logixlysia/ai'

const model = gateway('anthropic/claude-sonnet-4.5')

app.post('/chat', ({ log }) =>
  streamText({
    model: wrapLanguageModel({ model, middleware: aiMiddleware(log) }),
    prompt: 'Hello'
  }).toTextStreamResponse()
)

The usage goes on the access line when the model call finishes before the response does. Otherwise, as for the streamed response above, a later ai call finished line carries it; see AI SDK metrics. For an SDK the middleware does not cover, merge the numbers yourself:

import { mergeAIMetrics } from 'logixlysia/ai'

mergeAIMetrics(store.logger, request, {
  model: 'claude-sonnet',
  inputTokens: 100,
  outputTokens: 50,
  totalTokens: 150
})

Tracing

Add otelEnricher() from logixlysia/otel to config.enrichers, or call injectTraceContext from onRequest to merge the ids by hand (see OpenTelemetry).

Drains vs transports

evlog drains map to Logixlysia adapters, which are transports:

evlog drain Logixlysia adapter
evlog/axiom createAxiomTransport() from logixlysia/axiom
evlog/better-stack createBetterStackTransport() from logixlysia/better-stack
evlog/clickhouse createClickHouseTransport() from logixlysia/clickhouse
evlog/datadog createDatadogTransport() from logixlysia/datadog
evlog/hyperdx createHyperDXTransport() from logixlysia/hyperdx
evlog/loki createLokiTransport() from logixlysia/loki
evlog/otlp createOtlpTransport() from logixlysia/otlp
evlog/posthog createPostHogTransport() from logixlysia/posthog
evlog/sentry createSentryTransport() from logixlysia/sentry
import logixlysia from 'logixlysia'
import { createAxiomTransport } from 'logixlysia/axiom'

logixlysia({
  config: {
    transports: [createAxiomTransport()],
    useTransportsOnly: true
  }
})

File logging is built in (logFilePath) and logixlysia/testing has an in-memory transport for tests. Anything else without a matching adapter becomes a custom transport. Await your writer inside an async log, so flush and error reporting see its promise:

logixlysia({
  config: {
    transports: [
      {
        log: async (level, message, meta) => {
          await sendToService({ level, message, ...meta })
        }
      }
    ],
    useTransportsOnly: true
  }
})

Sampling

evlog’s sampling.rates maps to config.sampling.head with upper-case level names: debug, info, warn and error become DEBUG, INFO, WARNING and ERROR. Logixlysia has no trace or fatal level, so an evlog trace rate has no counterpart and must be removed, and an evlog fatal event, which evlog always keeps, becomes a log.error call, which is kept unless you set an ERROR rate below 100. An unknown key is rejected at startup. evlog’s sampling.keep rules map to config.sampling.tail: { status } to status, { duration } to durationMs, { path } to paths. A keep callback, which evlog awaits and which sets shouldKeep on its argument, becomes tail.keep: a synchronous predicate that returns true to keep the request and receives durationMs and pathname where evlog passes duration and path. Sampling describes it. Like every tail rule, tail.keep does nothing without head rates, and it runs only if no status, duration, or path rule matches.

logixlysia({
  config: {
    sampling: {
      head: { DEBUG: 1, INFO: 10 },
      tail: { status: 400, durationMs: 1000, paths: ['/checkout/**'] }
    }
  }
})

See Sampling.

Enrichers

config.enrichers runs contributors on every request that is not excluded from logging and merges their output into the request context. logixlysia/enrichers ships traceparentEnricher, userAgentEnricher, geoEnricher, sizeEnricher, and deploymentEnricher.

import logixlysia from 'logixlysia'
import { geoEnricher, traceparentEnricher } from 'logixlysia/enrichers'

logixlysia({
  config: {
    enrichers: [traceparentEnricher(), geoEnricher()]
  }
})

See Enrichers.

Structured errors

evlog’s createError({ message, why, fix }) maps to Logixlysia’s HttpError:

import { HttpError } from 'logixlysia'

throw new HttpError(402, 'Card declined', {
  code: 'PAYMENT_DECLINED',
  why: 'The issuing bank rejected the charge.',
  fix: 'Try a different card, or contact your bank.',
  link: 'https://docs.example.com/errors/payment-declined',
  internal: { gatewayCode: 'do_not_honor' }
})

code, why, fix, and link appear in both the log and the response. internal appears only in the log.

Was this page helpful?