重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
using-logging by andrelandgraf/fullstackrecipes
npx skills add https://github.com/andrelandgraf/fullstackrecipes --skill using-logging在整个应用程序中使用 Pino 进行结构化日志记录。涵盖日志级别、上下文和工作流安全的日志记录模式。
在整个应用程序中使用 Pino 进行结构化日志记录。涵盖日志级别、上下文和工作流安全的日志记录模式。
参见:
using-logging导入日志记录器并在整个应用程序中使用它:
import { logger } from "@/lib/logging/logger";
// 正常操作使用信息级别
logger.info("Server started", { port: 3000 });
// 可恢复问题使用警告级别
logger.warn("Rate limit reached", { endpoint: "/api/chat" });
// 错误级别配合 Error 对象使用
logger.error(err, "Failed to process request");
// 开发调试使用调试级别
logger.debug("Cache miss", { key: "user:123" });
始终将上下文作为结构化日志的第一个参数:
// 上下文对象在前,消息在后
logger.info({ userId: "123", action: "login" }, "User logged in");
// 对于错误,首先传递错误对象
logger.error({ err, userId: "123", endpoint: "/api/chat" }, "Request failed");
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
为不同场景使用适当的级别:
| 级别 | 使用时机 | | trace | 详细调试(很少使用) | | debug | 开发故障排除 | | info | 正常操作、业务事件 | | warn | 可恢复问题、弃用警告 | | error | 需要关注的故障 | | fatal | 严重故障,应用程序无法继续 |
设置 LOG_LEVEL 环境变量:
# 显示所有日志,包括调试信息
LOG_LEVEL="debug"
# 生产环境:仅显示警告和错误
LOG_LEVEL="warn"
如果未设置,默认为 info。有效值:trace、debug、info、warn、error、fatal。
import { logger } from "@/lib/logging/logger";
export async function POST(request: Request) {
const start = Date.now();
try {
const result = await processRequest(request);
logger.info(
{ duration: Date.now() - start, status: 200 },
"Request completed",
);
return Response.json(result);
} catch (err) {
logger.error({ err, duration: Date.now() - start }, "Request failed");
return Response.json({ error: "Internal error" }, { status: 500 });
}
}
工作流函数在受限环境中运行。使用日志记录器步骤包装器:
// src/workflows/chat/steps/logger.ts
import { logger } from "@/lib/logging/logger";
export async function log(
level: "info" | "warn" | "error" | "debug",
message: string,
data?: Record<string, unknown>,
): Promise<void> {
"use step";
if (data) {
logger[level](data, message);
} else {
logger[level](message);
}
}
然后在工作流中使用它:
import { log } from "./steps/logger";
export async function chatWorkflow({ chatId }) {
"use workflow";
await log("info", "Workflow started", { chatId });
}
每周安装量
52
代码仓库
GitHub 星标数
7
首次出现
2026年1月20日
安全审计
安装于
cursor41
opencode40
claude-code38
gemini-cli37
codex36
antigravity31
Use structured logging with Pino throughout your application. Covers log levels, context, and workflow-safe logging patterns.
Use structured logging with Pino throughout your application. Covers log levels, context, and workflow-safe logging patterns.
See:
using-logging in Fullstack RecipesImport the logger and use it throughout your application:
import { logger } from "@/lib/logging/logger";
// Info level for normal operations
logger.info("Server started", { port: 3000 });
// Warn level for recoverable issues
logger.warn("Rate limit reached", { endpoint: "/api/chat" });
// Error level with Error objects
logger.error(err, "Failed to process request");
// Debug level for development troubleshooting
logger.debug("Cache miss", { key: "user:123" });
Always include context as the first argument for structured logs:
// Context object first, message second
logger.info({ userId: "123", action: "login" }, "User logged in");
// For errors, pass the error first
logger.error({ err, userId: "123", endpoint: "/api/chat" }, "Request failed");
Use appropriate levels for different scenarios:
| Level | When to Use | | trace | Detailed debugging (rarely used) | | debug | Development troubleshooting | | info | Normal operations, business events | | warn | Recoverable issues, deprecation warnings | | error | Failures that need attention | | fatal | Critical failures, app cannot continue |
Set the LOG_LEVEL environment variable:
# Show all logs including debug
LOG_LEVEL="debug"
# Production: only warnings and errors
LOG_LEVEL="warn"
Default is info if not set. Valid values: trace, debug, info, warn, error, fatal.
import { logger } from "@/lib/logging/logger";
export async function POST(request: Request) {
const start = Date.now();
try {
const result = await processRequest(request);
logger.info(
{ duration: Date.now() - start, status: 200 },
"Request completed",
);
return Response.json(result);
} catch (err) {
logger.error({ err, duration: Date.now() - start }, "Request failed");
return Response.json({ error: "Internal error" }, { status: 500 });
}
}
Workflow functions run in a restricted environment. Use the logger step wrapper:
// src/workflows/chat/steps/logger.ts
import { logger } from "@/lib/logging/logger";
export async function log(
level: "info" | "warn" | "error" | "debug",
message: string,
data?: Record<string, unknown>,
): Promise<void> {
"use step";
if (data) {
logger[level](data, message);
} else {
logger[level](message);
}
}
Then use it in workflows:
import { log } from "./steps/logger";
export async function chatWorkflow({ chatId }) {
"use workflow";
await log("info", "Workflow started", { chatId });
}
Weekly Installs
52
Repository
GitHub Stars
7
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
cursor41
opencode40
claude-code38
gemini-cli37
codex36
antigravity31
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装
Karpathy LLM 编码指南 - 减少AI编程错误的行为准则与最佳实践
2,200 周安装
Eraser 图表生成器 - 从代码/描述自动生成专业架构图
2,100 周安装
caveman-compress:AI 文本压缩工具,优化 Claude 输入令牌,提升效率
2,200 周安装
mem CLI工具 - 本地智能记忆存储与全文搜索,提升开发效率
2,200 周安装
characteristic-voice:为AI助手注入真实情感与个性语音,打造会叹息会笑的伙伴
2,200 周安装
YouTube 字幕提取工具 - 一键获取视频字幕/时间戳,支持自动与手动字幕
2,200 周安装