### Install Dependencies and Start Dev Server Source: https://github.com/hugorcd/evlog/blob/main/apps/nitro-v2-playground/README.md Install project dependencies and start the development server. ```bash pnpm install pnpm run dev ``` -------------------------------- ### Clone and Run TanStack Start Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/05.tanstack-start.md Clone the evlog repository, navigate to the tanstack-start example directory, install dependencies, and run the development server. Access the demo at http://localhost:3000. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog/examples/tanstack-start pnpm install pnpm run dev ``` -------------------------------- ### Run Fastify Example Source: https://github.com/hugorcd/evlog/blob/main/examples/fastify/README.md Execute this command from the monorepo root to start the Fastify example. ```bash # From the monorepo root bun run example:fastify ``` -------------------------------- ### Install Dependencies and Start Development Server Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/README.md Use these npm commands to install project dependencies and start the local development server. The site will be accessible at http://localhost:3000. ```bash npm install # Start development server npm run dev ``` -------------------------------- ### Install and Run TanStack Start Project Source: https://github.com/hugorcd/evlog/blob/main/examples/tanstack-start/README.md Use these commands to install project dependencies and start the development server. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install Dependencies and Run Dev Server Source: https://github.com/hugorcd/evlog/blob/main/examples/browser/README.md Install project dependencies using bun install and start the development server with bun run dev. ```bash bun install bun run dev ``` -------------------------------- ### Clone and Run Fastify Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/09.fastify.md Clone the Evlog repository, navigate to the directory, install dependencies, and run the Fastify example. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:fastify ``` -------------------------------- ### Run SvelteKit Example Source: https://github.com/hugorcd/evlog/blob/main/examples/sveltekit/README.md Execute this command from the monorepo root to start the SvelteKit example application. Access the interactive UI at http://localhost:5173. ```bash # From the monorepo root bun run example:sveltekit ``` -------------------------------- ### Clone and Run Hono Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/08.hono.md Clone the Evlog repository and run the Hono example to explore the interactive test UI. This involves installing dependencies and starting the example server. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:hono ``` -------------------------------- ### Run evlog Express Example Source: https://github.com/hugorcd/evlog/blob/main/examples/express/README.md Execute this command from the monorepo root to start the Express example application. ```bash bun run example:express ``` -------------------------------- ### Run Development Server Source: https://github.com/hugorcd/evlog/blob/main/examples/orpc/README.md Starts the development server for the oRPC example. ```bash bun run dev ``` -------------------------------- ### Run oRPC Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/15.orpc.md Clone the repository, install dependencies, and run the oRPC example to test your integration. Access the interactive UI at http://localhost:3000. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:orpc ``` -------------------------------- ### Run SvelteKit Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/03.sveltekit.md Clone the Evlog repository, install dependencies, and run the SvelteKit example to explore the interactive test UI. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:sveltekit ``` -------------------------------- ### Full Setup Example for Next.js Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/5.enrichers.md Shows how to set up the Evlog logger with multiple enrichers, including trace context, within a Next.js application. ```typescript // lib/evlog.ts import { createEvlog } from 'evlog/next' import { createUserAgentEnricher, createGeoEnricher, createRequestSizeEnricher, createTraceContextEnricher, } from 'evlog/enrichers' const enrichers = [ createUserAgentEnricher(), createGeoEnricher(), createRequestSizeEnricher(), createTraceContextEnricher(), ] export const { withEvlog, useLogger, log, createError } = createEvlog({ service: 'my-app', enrich: (ctx) => { for (const enricher of enrichers) enricher(ctx) }, }) ``` -------------------------------- ### Full Setup Example for Standalone Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/5.enrichers.md Demonstrates initializing the Evlog logger with a set of enrichers, including trace context, in a standalone Node.js application. ```typescript // index.ts import { initLogger } from 'evlog' import { createUserAgentEnricher, createGeoEnricher, createRequestSizeEnricher, createTraceContextEnricher, } from 'evlog/enrichers' initLogger({ enrichers: [ createUserAgentEnricher(), createGeoEnricher(), createRequestSizeEnricher(), createTraceContextEnricher(), ], }) ``` -------------------------------- ### Run Next.js Evlog Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/02.nextjs.md Clone the Evlog repository, navigate to the Next.js example directory, install dependencies, and run the development server to test the integration. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog/examples/nextjs pnpm install pnpm run dev ``` -------------------------------- ### Run NestJS Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/06.nestjs.md Clone the evlog repository, install dependencies, and run the NestJS example using pnpm. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:nestjs ``` -------------------------------- ### Run Evlog React Router Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/11.react-router.md Clone the Evlog repository, install dependencies, and run the React Router example to explore the interactive test UI. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:react-router ``` -------------------------------- ### Run Express Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/07.express.md Clone the Evlog repository, install dependencies, and run the Express example using pnpm. Access the interactive test UI at http://localhost:3000. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:express ``` -------------------------------- ### Clone and Run Evlog Elysia Example Locally Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/10.elysia.md Clone the Evlog repository, navigate to the project directory, install dependencies, and run the Elysia example. Access the interactive UI at http://localhost:3000. ```bash git clone https://github.com/hugorcd/evlog.git cd evlog pnpm install pnpm run example:elysia ``` -------------------------------- ### Install evlog AI Skill Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/1.start/3.installation.md Install the evlog skill for your AI assistant to enable guided setup and code review. This command should be run in your terminal. ```bash npx skills add https://www.evlog.dev ``` -------------------------------- ### Start Documentation Site Source: https://github.com/hugorcd/evlog/blob/main/AGENTS.md Starts the documentation site, typically accessible on port 3000. ```bash pnpm run docs ``` -------------------------------- ### Full Setup Example for Hono / Express / Fastify / Elysia / NestJS Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/5.enrichers.md Provides integration examples for using multiple enrichers, including trace context, with various Node.js frameworks like Hono, Express, Fastify, Elysia, and NestJS. ```typescript import { createUserAgentEnricher, createGeoEnricher, createRequestSizeEnricher, createTraceContextEnricher, } from 'evlog/enrichers' const enrichers = [ createUserAgentEnricher(), createGeoEnricher(), createRequestSizeEnricher(), createTraceContextEnricher(), ] app.use(evlog({ enrichers })) // Hono / Express / Elysia // await app.register(evlog, { enrichers }) // Fastify // EvlogModule.forRoot({ enrichers }) // NestJS ``` -------------------------------- ### Start Development Server Source: https://github.com/hugorcd/evlog/blob/main/AGENTS.md Starts the development server for the playground environment. ```bash pnpm run dev ``` -------------------------------- ### Install Evlog and Run Wrangler Source: https://github.com/hugorcd/evlog/blob/main/examples/workers/README.md Install the evlog package and start the Cloudflare Workers development server. ```bash pnpm add evlog pnpm dlx wrangler dev ``` -------------------------------- ### Install and Run Tests Source: https://github.com/hugorcd/evlog/blob/main/examples/community-framework-skeleton/README.md Install dependencies and run the tests for the evlog-community-framework-skeleton. ```bash pnpm install pnpm --filter evlog-community-framework-skeleton test ``` -------------------------------- ### Install and Run Tests Source: https://github.com/hugorcd/evlog/blob/main/examples/community-adapter-skeleton/README.md Installs project dependencies and runs the test suite for the adapter skeleton. ```bash pnpm install pnpm --filter evlog-community-adapter-skeleton test ``` -------------------------------- ### Full Setup Example for Nuxt / Nitro Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/5.enrichers.md Demonstrates how to integrate multiple enrichers, including trace context, into a Nuxt/Nitro application by hooking into the 'evlog:enrich' event. ```typescript // server/plugins/evlog-enrich.ts import { createUserAgentEnricher, createGeoEnricher, createRequestSizeEnricher, createTraceContextEnricher, } from 'evlog/enrichers' export default defineNitroPlugin((nitroApp) => { const enrichers = [ createUserAgentEnricher(), createGeoEnricher(), createRequestSizeEnricher(), createTraceContextEnricher(), ] nitroApp.hooks.hook('evlog:enrich', (ctx) => { for (const enricher of enrichers) enricher(ctx) }) }) ``` -------------------------------- ### Install and Run Tests Source: https://github.com/hugorcd/evlog/blob/main/examples/community-enricher-skeleton/README.md Installs project dependencies and runs the tests for the evlog-community-enricher-skeleton using pnpm. ```bash pnpm install pnpm --filter evlog-community-enricher-skeleton test ``` -------------------------------- ### Install Evlog and Fastify Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/09.fastify.md Install the necessary packages for Evlog and Fastify using your preferred package manager. ```bash pnpm add evlog fastify ``` ```bash bun add evlog fastify ``` ```bash yarn add evlog fastify ``` ```bash npm install evlog fastify ``` -------------------------------- ### Build TanStack Start Project for Production Source: https://github.com/hugorcd/evlog/blob/main/examples/tanstack-start/README.md Run this command to create a production-ready build of your application. ```bash pnpm build ``` -------------------------------- ### Install Dependencies Source: https://github.com/hugorcd/evlog/blob/main/AGENTS.md Installs all project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install NuxtHub and Evlog Adapters Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/adapters/self-hosted/02.nuxthub.md Install both the NuxtHub core and the evlog NuxtHub adapter. This is the first step to integrating evlog with NuxtHub for log storage. ```bash pnpm add @nuxthub/core @evlog/nuxthub ``` -------------------------------- ### Initialize Evlog Client Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/1.client-logging.md Call initLog({ service: 'web' }) once at the application's start to initialize the Evlog client. This setup is framework-agnostic. ```typescript import { initLog } from '@evlog/client' initLog({ service: 'web' }) ``` -------------------------------- ### Run NestJS Example Source: https://github.com/hugorcd/evlog/blob/main/examples/nestjs/README.md Execute the NestJS example from the monorepo root using the provided bun command. Access the interactive UI at http://localhost:3000 to test routes. ```bash # From the monorepo root bun run example:nestjs ``` -------------------------------- ### Install Nuxthub and Evlog Adapter Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/adapters/self-hosted/02.nuxthub.md Install the necessary packages for Nuxthub core and the Evlog adapter using your preferred package manager. ```bash pnpm add @nuxthub/core @evlog/nuxthub ``` ```bash bun add @nuxthub/core @evlog/nuxthub ``` ```bash yarn add @nuxthub/core @evlog/nuxthub ``` ```bash npm install @nuxthub/core @evlog/nuxthub ``` -------------------------------- ### Install Evlog and Express Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/07.express.md Install the necessary packages for Evlog and Express using your preferred package manager. ```bash pnpm add evlog express ``` ```bash bun add evlog express ``` ```bash yarn add evlog express ``` ```bash npm install evlog express ``` -------------------------------- ### Add AI Observability with evlog Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/2.ai-sdk/01.overview.md Install the AI SDK, import and create an AI logger, and wrap your model to automatically capture AI metrics. This setup provides insights into token usage, tool calls, and streaming performance. ```bash pnpm add ai ``` -------------------------------- ### Direct OTLP API Usage Examples Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/adapters/cloud/02.otlp.md Examples demonstrating how to send single or batch events using the OTLP adapter. Also shows how to convert an event to OTLP format for inspection. Ensure the endpoint is correctly configured. ```typescript import { sendToOTLP, sendBatchToOTLP, toOTLPLogRecord } from 'evlog/otlp' // Send a single event await sendToOTLP(event, { endpoint: 'http://localhost:4318', }) // Send multiple events await sendBatchToOTLP(events, { endpoint: 'http://localhost:4318', }) // Convert event to OTLP format (for inspection) const otlpRecord = toOTLPLogRecord(event) ``` -------------------------------- ### Install Evlog and React Router Packages Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/11.react-router.md Install the necessary Evlog and React Router packages using your preferred package manager. ```bash pnpm add evlog react-router @react-router/node @react-router/serve ``` ```bash bun add evlog react-router @react-router/node @react-router/serve ``` ```bash yarn add evlog react-router @react-router/node @react-router/serve ``` ```bash npm install evlog react-router @react-router/node @react-router/serve ``` -------------------------------- ### Hono / Express / Fastify / Elysia / NestJS Evlog Setup Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/5.extend/9.drain-pipeline.md Configures the Evlog drain pipeline for various Node.js frameworks. Includes examples for Hono, Express, Elysia, Fastify, and NestJS. Remember to flush the pipeline on SIGTERM. ```typescript import type { DrainContext } from 'evlog' import { createDrainPipeline } from 'evlog/pipeline' import { createAxiomDrain } from 'evlog/axiom' const pipeline = createDrainPipeline() const drain = pipeline(createAxiomDrain()) app.use(evlog({ drain })) // Hono / Express / Elysia // await app.register(evlog, { drain }) // Fastify // EvlogModule.forRoot({ drain }) // NestJS process.on('SIGTERM', () => drain.flush()) ``` -------------------------------- ### Install Evlog and ORPC Server Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/15.orpc.md Install the necessary packages for Evlog and the ORPC server using your preferred package manager. ```bash pnpm add evlog @orpc/server ``` ```bash bun add evlog @orpc/server ``` ```bash yarn add evlog @orpc/server ``` ```bash npm install evlog @orpc/server ``` -------------------------------- ### Example Wide Event Log Output Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/01.nuxt.md This is an example of the consolidated log output for a single request after using `useLogger` to set various context fields. ```bash 10:23:45 INFO [my-app] POST /api/checkout 200 in 145ms ├─ user: id=usr_123 plan=enterprise ├─ cart: items=3 total=14999 ├─ payment: method=card cardLast4=4242 └─ requestId: a1b2c3d4-... ``` -------------------------------- ### Install Evlog Package Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/04.nitro.md Install the Evlog package using your preferred package manager. ```bash pnpm add evlog ``` ```bash bun add evlog ``` ```bash yarn add evlog ``` ```bash npm install evlog ``` -------------------------------- ### Install Evlog and Elysia Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/10.elysia.md Install the necessary packages for Evlog and Elysia using your preferred package manager. ```bash pnpm add evlog elysia ``` ```bash bun add evlog elysia ``` ```bash yarn add evlog elysia ``` ```bash npm install evlog elysia ``` -------------------------------- ### Install Evlog and Hono Dependencies Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/08.hono.md Install the necessary packages for Evlog and Hono using your preferred package manager. ```bash pnpm add evlog hono @hono/node-server ``` ```bash bun add evlog hono @hono/node-server ``` ```bash yarn add evlog hono @hono/node-server ``` ```bash npm install evlog hono @hono/node-server ``` -------------------------------- ### Install AI SDK Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/2.ai-sdk/01.overview.md Add the AI SDK as a dependency using your preferred package manager. ```bash pnpm add ai ``` ```bash bun add ai ``` ```bash yarn add ai ``` ```bash npm install ai ``` -------------------------------- ### TanStack Start Configuration with Evlog Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/skills/review-logging-patterns/SKILL.md Set up Evlog for TanStack Start by configuring `nitro.config.ts` and adding error handling middleware. ```typescript // nitro.config.ts import { defineConfig } from 'nitro' import evlog from 'evlog/nitro/v3' export default defineConfig({ experimental: { asyncContext: true }, modules: [evlog({ env: { service: 'my-app' } })], }) ``` ```typescript // src/routes/__root.tsx import { createMiddleware } from '@tanstack/react-start' import { evlogErrorHandler } from 'evlog/nitro/v3' export const Route = createRootRoute({ server: { middleware: [createMiddleware().server(evlogErrorHandler)], }, }) ``` -------------------------------- ### Install Axiom Drain Adapter Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/adapters/cloud/01.axiom.md Import the createAxiomDrain function from the evlog/axiom package to set up the Axiom adapter. ```typescript import { createAxiomDrain } from 'evlog/axiom' ``` -------------------------------- ### Traditional logging example Source: https://github.com/hugorcd/evlog/blob/main/apps/just-use-evlog/content/landing.md Demonstrates a typical, unhelpful logging output from a server handler. This example shows multiple INFO, WARN, and ERROR messages that lack context and narrative. ```bash $ node server.js INFO Starting handler INFO user loaded INFO db query ok WARN slow??? ERROR Payment failed ERROR Error: undefined INFO done ``` -------------------------------- ### Install Better Auth Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/3.better-auth/01.overview.md Install the Better Auth dependency for your project using your preferred package manager. ```bash pnpm add better-auth ``` ```bash bun add better-auth ``` ```bash yarn add better-auth ``` ```bash npm install better-auth ``` -------------------------------- ### Install evlog with bun Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/1.start/3.installation.md Use this command to add evlog to your project if you are using bun as your package manager. ```bash bun add evlog ``` -------------------------------- ### HTTP Drain Quick Start Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/5.extend/9.drain-pipeline.md Quick start example for setting up the HTTP transport for client-side logs. It initializes the logger with a pre-configured HTTP drain that sends logs to a specified endpoint. ```typescript import { initLogger, log } from 'evlog' import { createHttpLogDrain } from 'evlog/http' const drain = createHttpLogDrain({ drain: { endpoint: 'https://logs.example.com/v1/ingest' } }) initLogger({ drain }) log.info({ action: 'page_view', path: location.pathname }) ``` -------------------------------- ### Run Development Server (Monorepo Root) Source: https://github.com/hugorcd/evlog/blob/main/apps/just-use-evlog/README.md Start the development server for the 'just-use-evlog' app from the monorepo root directory. ```bash pnpm run dev:just-use-evlog ``` -------------------------------- ### Create an API Route with TanStack Start Source: https://github.com/hugorcd/evlog/blob/main/examples/tanstack-start/README.md Define API routes by specifying the 'server' property in route definitions. This example creates a '/api/hello' route that responds with a JSON message. ```tsx import { createFileRoute } from '@tanstack/react-router' import { json } from '@tanstack/react-start' export const Route = createFileRoute('/api/hello')({ server: { handlers: { GET: () => json({ message: 'Hello, World!' }), }, }, }) ``` -------------------------------- ### Multi-hook Plugin Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/5.extend/4.plugins.md Define a plugin that hooks into multiple event lifecycle stages for comprehensive tracking, such as request metrics. Ensure `statsd` is initialized and available in the `setup` hook. ```typescript import { definePlugin } from 'evlog/toolkit' export const requestMetricsPlugin = definePlugin({ name: 'request-metrics', setup({ env }) { statsd.init({ service: env.service }) }, enrich({ event }) { event.tier = event.duration && event.duration > 1000 ? 'slow' : 'fast' }, drain({ event }) { statsd.timing('http.request', event.duration as number, { path: event.path as string }) }, onRequestStart({ logger, request }) { logger.set({ trace: { startedAt: Date.now() } }) }, onRequestFinish({ event, durationMs }) { if (event && (event.level === 'error' || durationMs > 5000)) { // alert / forward / etc. } }, }) ``` -------------------------------- ### Create a Server Function with TanStack Start Source: https://github.com/hugorcd/evlog/blob/main/examples/tanstack-start/README.md Define server functions using createServerFn to handle server-side logic that can be seamlessly called from client components. This example fetches the current server time. ```tsx import { createServerFn } from '@tanstack/react-start' const getServerTime = createServerFn({ method: 'GET', }).handler(async () => { return new Date().toISOString() }) // Use in a component function MyComponent() { const [time, setTime] = useState('') useEffect(() => { getServerTime().then(setTime) }, []) return
Server time: {time}
} ``` -------------------------------- ### Hono/Express/Fastify/Standalone Stream Server Setup Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/5.extend/1.stream.md For frameworks like Hono, Express, Fastify, or standalone Node.js applications, start the stream server manually and register its drain hook. Ensure it's only enabled in development environments. ```typescript import { startStreamServer } from 'evlog/stream' if (process.env.NODE_ENV !== 'production' && process.env.EVLOG_STREAM === '1') { const { drain } = await startStreamServer() // Plug `drain` into the evlog drain hook for your framework } ``` -------------------------------- ### Build for Production Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/README.md Run this npm command to build the project for production. The output will be placed in the '.output' directory, ready for deployment. ```bash npm run build ``` -------------------------------- ### Build for Deployment Source: https://github.com/hugorcd/evlog/blob/main/apps/nitro-v2-playground/README.md Build the project for deployment. ```bash pnpm run build ``` -------------------------------- ### Terminal Output Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/13.standalone.md Example of how structured logs appear in the terminal after processing. ```bash 14:58:15 INFO [migrate] user-migration ├─ migrated: 1250 ├─ found: 1250 ├─ status: complete └─ task: user-migration ``` -------------------------------- ### Initialize Evlog Logger with Global Options Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/6.reference/1.configuration.md Configure Evlog globally at application startup using `initLogger`. This example sets essential options like enabling logging, defining environment context, disabling pretty printing, and configuring sampling and drains. ```typescript import { initLogger } from 'evlog' import { createAxiomDrain } from 'evlog/axiom' initLogger({ enabled: true, env: { service: 'my-api', environment: 'production' }, pretty: false, silent: false, stringify: true, minLevel: 'info', sampling: { rates: { info: 10 }, keep: [{ status: 400 }] }, drain: createAxiomDrain(), }) ``` -------------------------------- ### Basic AI SDK Logging Setup Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/skills/review-logging-patterns/SKILL.md Use `createAILogger` to wrap your logger and `ai.wrap` to transparently capture LLM calls from the AI SDK. This is suitable for basic token usage and model info logging. ```typescript import { createAILogger } from 'evlog/ai' const log = useLogger(event) // or any RequestLogger const ai = createAILogger(log) const result = streamText({ model: ai.wrap('anthropic/claude-sonnet-4.6'), // accepts string or model object messages, }) ``` -------------------------------- ### AI SDK Cost Estimation Setup Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/skills/review-logging-patterns/SKILL.md Provide a pricing map to `createAILogger` to enable `ai.estimatedCost` logging. This helps in tracking the cost associated with AI model usage. ```typescript const ai = createAILogger(log, { cost: { 'claude-sonnet-4.6': { input: 3, output: 15 }, 'gpt-4o': { input: 2.5, output: 10 }, }, }) ``` -------------------------------- ### Install Evlog for NestJS Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/06.nestjs.md Install the evlog package along with necessary NestJS dependencies using your preferred package manager. ```bash pnpm add evlog @nestjs/common @nestjs/core @nestjs/platform-express ``` ```bash bun add evlog @nestjs/common @nestjs/core @nestjs/platform-express ``` ```bash yarn add evlog @nestjs/common @nestjs/core @nestjs/platform-express ``` ```bash npm install evlog @nestjs/common @nestjs/core @nestjs/platform-express ``` -------------------------------- ### Install Nuxthub and Evlog Adapter with Nuxi Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/adapters/self-hosted/02.nuxthub.md Alternatively, use the nuxi command to add the Nuxthub core and Evlog adapter modules to your project. ```bash npx nuxi module add @nuxthub/core @evlog/nuxthub ``` -------------------------------- ### Access Logger in TanStack Start Request Context Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/skills/review-logging-patterns/SKILL.md Retrieve the logger instance in TanStack Start using `useRequest()` from `nitro/context`. ```typescript import { useRequest } from 'nitro/context' import type { RequestLogger } from 'evlog' const req = useRequest() const log = req.context.log as RequestLogger log.set({ user: { id: 'user_123' } }) ``` -------------------------------- ### Build Package Source: https://github.com/hugorcd/evlog/blob/main/AGENTS.md Builds the main evlog package. ```bash pnpm run build:package ``` -------------------------------- ### Example Event with Trace Context Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/5.enrichers.md Illustrates an example event output that includes the 'traceContext' object, along with top-level 'traceId' and 'spanId' fields. ```json { "traceContext": { "traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b7" }, "traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b7" } ``` -------------------------------- ### Run Tests in TanStack Start Project Source: https://github.com/hugorcd/evlog/blob/main/examples/tanstack-start/README.md Execute this command to run all defined tests using Vitest. ```bash pnpm test ``` -------------------------------- ### Wide Event Log Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/4.use-cases/2.ai-sdk/01.overview.md Example of a wide event log entry, including AI-specific details like model, tokens, and performance metrics. ```json { "method": "POST", "path": "/api/chat", "status": 200, "duration": "4.5s", "ai": { "calls": 1, "model": "claude-sonnet-4.6", "provider": "anthropic", "inputTokens": 3312, "outputTokens": 814, "totalTokens": 4126, "reasoningTokens": 225, "finishReason": "stop", "msToFirstChunk": 234, "msToFinish": 4500, "tokensPerSecond": 180 } } ``` -------------------------------- ### Cloudflare Worker Log Output Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/3.integrate/frameworks/12.cloudflare-workers.md Example of structured log output from a Cloudflare Worker using Evlog, showing request details and context. ```bash 14:58:15 INFO [my-worker] GET /api/users 200 in 12ms ├─ orders: count=5 ├─ user: id=usr_123 plan=pro ├─ route: /api/users └─ requestId: 4a8ff3a8-... ``` -------------------------------- ### Run evlog Benchmarks in Terminal Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/6.reference/2.performance.md Commands to execute all benchmarks, compare against alternatives, or measure bundle size. ```bash cd packages/evlog pnpm run bench # all benchmarks pnpm exec vitest bench bench/comparison/ # vs alternatives only pnpm exec tsx bench/scripts/size.ts # bundle size ``` -------------------------------- ### Wide Event Output Example Source: https://github.com/hugorcd/evlog/blob/main/apps/docs/content/2.learn/2.wide-events.md Demonstrates the consolidated output of a wide event, showing all set context, operation details, and status in a single, readable log entry. ```bash [INFO] POST /api/checkout (234ms) user: { id: 1, plan: 'pro' } cart: { id: 42, items: 3, total: 9999 } payment: { method: 'card', status: 'success' } status: 200 ```