Logging System Guide

VerifiedSafe

Comprehensive guide to application logging, script logging, error monitoring, and request logging, with best practices.

Sby Skills Guide Bot
DevelopmentIntermediate
8/11/2026
Claude CodeCursorWindsurfCopilotCodex
#logging#error-monitoring#observability#frontend#debugging

Recommended for

Automated summary

A project-specific guide to application and script logging, error monitoring and reporting, and HTTP request logs, with usage examples and best practices.

Strengths

  • Covers four complementary layers: script logs, application logs, error capture, and request logs.
  • Provides concrete usage snippets for internal packages and HTTP interceptors.
  • Highlights key practices: correct log levels, useful context, and avoiding sensitive data.
  • Explains error classification and how to view or export captured errors.

Limitations

  • Tightly coupled to a specific project’s package paths and apps (@build-utils/logger, @btc/shared-core, operations-app).
  • Assumes a Vue/Vite stack and internal components, with limited guidance for adapting to another codebase.
  • Does not describe the internal implementation of the loggers, localStorage storage, or Excel export.
When to use it

Use this when you need to add or standardize logging, capture errors, or inspect HTTP requests in this project.

When not to use it

Avoid it if you need a generic logging solution independent of this codebase or server-side observability configuration.

Security analysis

Safe
Quality score85/100

The skill is a documentation guide about logging systems, including code examples and best practices. It contains no dangerous instructions, no shell commands, no exfiltration, or any actions that could compromise security. It is purely informational.

No concerns found

How this analysis is made

Examples

Capture a business error
Add error monitoring around the save flow and report a failed save as a business error with useful context, then show the user an error message.
Log an order safely
Show how to log an order creation with the project logger, including orderId, userId, and amount, while keeping sensitive data out of the logs.
Inspect request logs
How can I retrieve and export the HTTP request logs in this app using the request-logger utility?

name: logging-system description: 'description: 日志系统完整指南,包括应用日志、脚本日志、错误监控上报、请求日志等'

--- name: logging-system description: 日志系统完整指南,包括应用日志、脚本日志、错误监控上报、请求日志等

日志系统

何时使用

当你需要:

  • 记录应用日志
  • 监控和上报错误
  • 查看请求日志
  • 调试问题
  • 分析用户行为

项目日志架构

1. 脚本日志(@build-utils/logger)

用途:构建脚本、部署脚本的日志输出 位置:packages/@build-utils/logger/

使用: import { logger } from '@build-utils/logger'

logger.info('构建开始') logger.warn('警告信息') logger.error('错误信息') logger.success('操作成功')

特点:

  • 带时间戳
  • 彩色输出
  • 支持子logger

2. 应用日志(shared-core/logger)

用途:前端应用的日志记录 位置:packages/shared-core/src/logger/

使用: import { logger } from '@btc/shared-core'

logger.info('用户登录', { username: 'admin' }) logger.warn('Token即将过期') logger.error('API调用失败', error)

日志级别:

  • debug:调试信息(开发环境)
  • info:一般信息
  • warn:警告
  • error:错误

3. 错误监控系统

用途:捕获、上报、分析前端错误 位置:packages/shared-core/src/utils/error-monitor/

功能: ✅ 自动捕获 JS 错误 ✅ 捕获 Promise 未处理的 rejection ✅ 捕获 Vue 组件错误 ✅ 存储到 localStorage ✅ 导出错误报告

使用: import { captureError, getErrorList } from '@btc/shared-core'

// 手动上报错误 captureError(new Error('自定义错误'), { type: 'business', context: { userId: 123 } })

// 获取错误列表 const errors = getErrorList()

4. 请求日志(request-logger)

用途:记录所有 HTTP 请求 位置:apps/{app}/src/utils/request-logger.ts

功能: ✅ 记录请求 URL、方法、参数 ✅ 记录响应状态、耗时 ✅ 自动过滤敏感信息 ✅ 支持查询和导出

使用(自动集成): HTTP 拦截器自动记录所有请求 无需手动调用

查看日志: import { getRequestLogs } from '@/utils/request-logger' const logs = getRequestLogs()

错误监控使用

自动错误捕获

在应用入口(main.ts)中已自动启用: import { initErrorMonitor } from '@btc/shared-core'

initErrorMonitor({ appName: 'admin-app', version: '1.0.0', onError: (error) => { // 可选:上报到服务器 console.error('Error captured:', error) } })

手动上报

业务错误: try { await saveData(data) } catch (error) { captureError(error, { type: 'business', context: { operation: 'save', data } }) BtcMessage.error('保存失败') }

网络错误: fetch('/api/data') .catch(error => { captureError(error, { type: 'network' }) })

组件错误: onErrorCaptured((error, instance, info) => { captureError(error, { type: 'component', context: { component: instance?.$.type.name, info } }) })

错误查看和导出

查看错误列表: 访问:operations-app 的错误监控页面 路径:/operations/error-monitor

导出错误: 使用 BtcErrorMonitorExport 组件 支持按日期、来源、类型筛选导出

日志级别配置

开发环境

// vite.config.ts define: { LOG_LEVEL: JSON.stringify('debug') }

所有级别日志都输出

生产环境

define: { LOG_LEVEL: JSON.stringify('warn') }

只输出 warn 和 error

日志最佳实践

1. 使用正确的日志级别

logger.debug('变量值', { value }) // 调试信息 logger.info('用户登录成功') // 操作记录 logger.warn('Token即将过期') // 警告 logger.error('保存失败', error) // 错误

2. 包含上下文信息

logger.info('订单创建', { orderId: order.id, userId: user.id, amount: order.amount })

3. 避免敏感信息

❌ logger.info('用户密码', { password: '123456' }) ✅ logger.info('用户登录', { username: 'admin' })

4. 使用错误监控

try { await riskyOperation() } catch (error) { captureError(error, { type: 'business', context: {...} }) // 然后处理错误 }

错误分类

项目支持的错误类型:

  • network:网络错误
  • api:API调用错误
  • business:业务逻辑错误
  • component:组件错误
  • runtime:运行时错误
  • resource:资源加载错误

查看日志的位置

浏览器控制台

开发环境所有日志都在控制台

错误监控页面

访问:http://localhost:5109/operations/error-monitor

功能:

  • 查看所有捕获的错误
  • 按来源、类型、时间筛选
  • 导出错误报告 Excel
  • 清除错误记录

localStorage

错误存储: Key: btc_error 格式:{ errors: { [date]: FormattedError[] } }

查看: 浏览器 DevTools > Application > Local Storage

请求日志

查看请求日志

import { getRequestLogs } from '@/utils/request-logger'

const logs = getRequestLogs() console.table(logs)

日志内容

每条日志包含:

  • url: 请求URL
  • method: 请求方法
  • status: 响应状态
  • duration: 耗时(ms)
  • timestamp: 时间戳
  • params: 请求参数(脱敏)
  • response: 响应数据(部分)

日志导出

import { exportRequestLogs } from '@/utils/request-logger' exportRequestLogs() // 导出为 Excel

性能监控

关键指标日志

logger.info('页面加载耗时', { loadTime: performance.now() })

logger.info('API调用耗时', { api: '/api/data', duration: 350 })

用户行为日志

logger.info('用户操作', { action: 'click', target: 'save-button', module: 'warehouse' })

日志存储策略

前端

  • Console:开发环境所有日志
  • localStorage:错误日志(最近7天)
  • IndexedDB:请求日志(可选,未启用)

后端(建议)

  • 创建日志上报 API
  • 批量上报错误日志
  • 存储到数据库或日志服务

集成第三方日志服务(可选)

Sentry

pnpm add @sentry/vue

import * as Sentry from '@sentry/vue'

Sentry.init({ app, dsn: 'your-sentry-dsn', integrations: [ new Sentry.BrowserTracing(), ], tracesSampleRate: 1.0, })

其他选项

  • 阿里云日志服务(SLS)
  • 腾讯云日志服务(CLS)
  • ELK Stack
  • Grafana Loki

常见问题

Q: 如何查看某个应用的所有错误? A: 访问 operations-app 错误监控页面,按来源筛选

Q: 日志太多影响性能? A: 生产环境设置 LOG_LEVEL=warn,减少日志输出

Q: 如何上报到服务器? A: 在 initErrorMonitor 的 onError 回调中发送API请求

Q: 请求日志存哪里? A: 内存中(可配置存储到 localStorage)

相关工具

查看错误统计: 访问 operations-app 错误监控页面

导出错误报告: 使用 BtcErrorMonitorExport 组件

清理旧日志: localStorage.removeItem('btc_error')

下一步

需要排查错误?→ 使用 troubleshooting 技能 需要导出日志?→ 使用 excel-toolkit 技能

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/logging-system-guide-mso6xgnv/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/logging-system-guide-mso6xgnv' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/logging-system-guide-mso6xgnv/download' --output '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md.part' && mv '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md.part' '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && test -s '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/logging-system' && cp -R '.skill-downloads/logging-system-guide-mso6xgnv' '.claude/skills/logging-system'

Cursor
test -f '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && test -s '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/logging-system' && cp -R '.skill-downloads/logging-system-guide-mso6xgnv' '.cursor/skills/logging-system'

Codex
test -f '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && test -s '.skill-downloads/logging-system-guide-mso6xgnv/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/logging-system' && cp -R '.skill-downloads/logging-system-guide-mso6xgnv' '.agents/skills/logging-system'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/logging-system-guide-mso6xgnv'

openskills read 'logging-system-guide-mso6xgnv'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/logging-system-guide-mso6xgnv/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills