---
title: "安装 evlog"
description: "在 TypeScript 项目中安装 evlog。支持 Nuxt、Next.js、SvelteKit、Hono、Express、Fastify、Elysia、NestJS 以及独立脚本。"
canonical_url: "https://evlog.zhcndoc.com/start/installation"
---
# 安装 evlog

> 在 TypeScript 项目中安装 evlog。支持 Nuxt、Next.js、SvelteKit、Hono、Express、Fastify、Elysia、NestJS 以及独立脚本。

evlog 支持 Nuxt、Next.js、SvelteKit、Nitro、NestJS 以及任何 TypeScript 服务端框架。

<prompt :actions="["copy","cursor","claude"]" description="在我的项目中安装 evlog" icon="i-lucide-download">

在我的 TypeScript 项目中安装 evlog。

- 检测我正在使用的框架（Nuxt、Next.js、SvelteKit、Nitro、NestJS、Express、Hono、Fastify、Elysia、TanStack Start、React Router、Cloudflare Workers，或独立项目）
- 使用我的包管理器安装 evlog：pnpm add evlog（或 npm/yarn/bun）
- 使用 defineEvlog 创建 evlog.config.ts，并将 service 设置为我的应用名称
- 接入特定于框架的集成（模块、插件或中间件），使其加载 evlog.config.ts
- 确认 useLogger、createError 和 parseError 可用

文档：[https://www.evlog.dev/start/installation](https://www.evlog.dev/start/installation)
框架：[https://www.evlog.dev/integrate/frameworks/overview](https://www.evlog.dev/integrate/frameworks/overview)

</prompt>

## 安装

<code-group>

```bash [pnpm]
pnpm add evlog
```

```bash [bun]
bun add evlog
```

```bash [yarn]
yarn add evlog
```

```bash [npm]
npm install evlog
```

</code-group>

### 使用 Agent 技能

如果你使用了 AI 助手（如 Claude Code、Cursor 等），安装 evlog 技能以获得引导式设置和代码审查：

```bash [Terminal]
npx skills add https://www.evlog.dev
```

你的 AI 助手随后可以帮助你设置 evlog、审查你的日志记录模式，并将现有代码迁移到宽事件。有关详细信息，请参阅 [Agent Skills](https://evlog.zhcndoc.com/reference/agent-skills)。

<callout color="neutral" icon="i-lucide-radar">

**试试 evlog map。** `evlog` 可执行文件随软件包提供。虽然还处于早期阶段，但只需一条命令即可评估哪些入口点仍然没有日志记录：

```bash
npx evlog map
# 或：pnpm evlog map
```

查看 [CLI 概览](https://evlog.zhcndoc.com/cli/overview) 和 [`evlog map`](https://evlog.zhcndoc.com/cli/map)

</callout>

## 创建配置

运行 `npx evlog init`，或手动在应用根目录添加 `evlog.config.ts`：

```typescript [evlog.config.ts]
import { defineEvlog } from 'evlog'

export default defineEvlog({
  service: 'my-app',
})
```

这个文件包含所有选项：采样、drain、增强器和路由过滤器。对应的框架指南会说明如何加载它。请参阅[配置](https://evlog.zhcndoc.com/reference/configuration)。

## 接入你的框架

安装包后，按照对应框架的设置指南进行操作：

<card-group>
<card color="neutral" icon="i-simple-icons-nuxtdotjs" title="Nuxt" to="https://evlog.zhcndoc.com/integrate/frameworks/nuxt">

自动导入 `useLogger` 和 `parseError` 的模块。

</card>

<card color="neutral" icon="i-simple-icons-nextdotjs" title="Next.js" to="https://evlog.zhcndoc.com/integrate/frameworks/nextjs">

`createEvlog()` 工厂函数与 `withEvlog()` 处理程序包装器。

</card>

<card color="neutral" icon="i-simple-icons-svelte" title="SvelteKit" to="https://evlog.zhcndoc.com/integrate/frameworks/sveltekit">

使用 `event.locals.log` 的 `handle` 与 `handleError` 钩子。

</card>

<card color="neutral" icon="i-custom-nitro" title="Nitro" to="https://evlog.zhcndoc.com/integrate/frameworks/nitro">

适用于 Nitro v2 和 v3 的插件式钩子模块。

</card>

<card color="neutral" icon="i-custom-tanstack" title="TanStack Start" to="https://evlog.zhcndoc.com/integrate/frameworks/tanstack-start">

使用 Nitro v3 模块与异步上下文。

</card>

<card color="neutral" icon="i-custom-reactrouter" title="React Router" to="https://evlog.zhcndoc.com/integrate/frameworks/react-router">

使用 `context.get(loggerContext)` 的中间件。

</card>

<card color="neutral" icon="i-simple-icons-nestjs" title="NestJS" to="https://evlog.zhcndoc.com/integrate/frameworks/nestjs">

使用全局中间件的 `EvlogModule.forRoot()`。

</card>

<card color="neutral" icon="i-simple-icons-express" title="Express" to="https://evlog.zhcndoc.com/integrate/frameworks/express">

使用 `req.log` 的中间件。

</card>

<card color="neutral" icon="i-simple-icons-hono" title="Hono" to="https://evlog.zhcndoc.com/integrate/frameworks/hono">

使用 `c.get('log')` 的中间件。

</card>

<card color="neutral" icon="i-simple-icons-fastify" title="Fastify" to="https://evlog.zhcndoc.com/integrate/frameworks/fastify">

使用 `request.log` 的插件。

</card>

<card color="neutral" icon="i-custom-elysia" title="Elysia" to="https://evlog.zhcndoc.com/integrate/frameworks/elysia">

使用 `log` 作为路由上下文的插件。

</card>

<card color="neutral" icon="i-lucide-network" title="oRPC" to="https://evlog.zhcndoc.com/integrate/frameworks/orpc">

`withEvlog()` 处理程序包装器 + `evlog()` 过程处理程序中间件。

</card>

<card color="neutral" icon="i-simple-icons-cloudflare" title="Cloudflare Workers" to="https://evlog.zhcndoc.com/integrate/frameworks/cloudflare-workers">

用于请求作用域日志记录器的工厂函数。

</card>
</card-group>

<callout color="neutral" icon="i-lucide-arrow-right">

查看完整的 [框架集成](https://evlog.zhcndoc.com/integrate/frameworks/overview) 页面，以获取对比表和所有可用集成，包括 [Standalone TypeScript](https://evlog.zhcndoc.com/integrate/frameworks/standalone)、[Astro](https://evlog.zhcndoc.com/integrate/frameworks/astro) 以及 [Custom Integration](https://evlog.zhcndoc.com/extend/custom-framework)。

</callout>

## 为你添加的字段提供类型

evlog 附带完整的 TypeScript 类型定义，无需额外配置。

<callout color="success" icon="i-lucide-check">

evlog 需要 TypeScript 5.0 或更高版本以获得最佳的类型推断。

</callout>

## 下一步

- [快速开始](https://evlog.zhcndoc.com/start/quick-start) - 了解核心概念并开始使用 evlog
- [宽事件](https://evlog.zhcndoc.com/learn/wide-events) - 理解宽事件模式
- [适配器](https://evlog.zhcndoc.com/integrate/adapters/overview) - 将日志发送到 Axiom、PostHog、Sentry 等。

---

- [框架](https://evlog.zhcndoc.com/integrate/frameworks/overview)


## Sitemap

See the full [sitemap](https://evlog.zhcndoc.com/sitemap.md) for all pages.
