13-code-logging-standards

A set of rules for generating Java code with detailed Chinese comments and execution logs. It requires the Lombok Slf4j logging framework and defines when to use information, debug, warning, and error logs.

In plain words
What is it for?
Use it when writing or reviewing Java classes, methods, fields, branches, controllers, and business operations that need Chinese documentation and structured logs.
Why use it?
It gives a consistent standard for explaining Java code and recording what the application is doing. This can make code review and diagnosis easier for teams that use these conventions.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/movebrickschi/harness-engineering-mcp/13-code-logging-standards
Clone the repo
git clone --depth 1 https://github.com/movebrickschi/harness-engineering-mcp
Per session 999 This file is loaded in full into every session.
When invoked 999 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00999 $0.00999
Opus 5 $0.00500 $0.00500
Sonnet 5 $0.00200 $0.00200
Haiku 4.5 $0.00100 $0.00100

Measured 2d ago against content hash da7b25e20e11, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

13-code-logging-standards scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

assets/rules/13-code-logging-standards.mdc · 118 lines

How it starts

The opening of the file, as written. The whole thing — 118 lines — stays where its author put it; the contents beside it link to each section on GitHub.

中文注释 + 代码执行日志规范

一、中文注释要求

每个类、公开方法、字段都必须有中文说明(详见 05-chinese-comments 规则),以下是补充强调:

  • 关键 if/else 分支必须有一句中文说明其判断意图
  • 非显而易见的常量、魔法数字必须注释说明含义
  • 不要写只是重复代码语义的废注释(如 // 调用 insert 方法

二、日志框架使用

统一使用 @Slf4j(Lombok),禁止直接使用 System.out.println

// ✅ 正确
@Slf4j
@Service
public class OrderService {
    public void createOrder(...) {
        log.info("[订单服务] 创建订单,userId={}, amount={}", userId, amount);
    }
}

// ❌ 禁止
System.out.println("创建订单: " + userId);

三、日志级别选择

级别 使用场景
log.info 写操作入口(新增/更新/删除)、关键业务节点(登录、支付、状态变更)、操作结果
log.debug 读操作入口、中间过程、循环内部、查询结果
log.warn 业务校验失败、数据异常、可降级的外部调用失败
log.error 系统异常、需要立即处理的错误,必须附带异常对象 log.error("...", e)

四、各层日志埋点规范

Controller 层

// 写操作:方法入口用 info,完成用 info
@PostMapping
public R<SysUser> createUser(@RequestBody SysUser user) {
    log.info("[用户控制器] 新增用户,username={}", user.getUsername());
    // ... 业务逻辑 ...
    log.info("[用户控制器] 用户新增成功,userId={}", user.getId());
    return R.ok(user);
}

// 读操作:方法入口用 debug,完成用 debug
@GetMapping("/list")
public R<IPage<SysUser>> list(...) {
    log.debug("[用户控制器] 查询用户列表,page={}, size={}", page, size);
    // ...
    log.debug("[用户控制器] 用户列表查询完成,总数={}", result.getTotal());
    return R.ok(result);
}

Service 层

// 复杂业务流程中的关键步骤各打一条日志
@Transactional
public void assignRoleMenus(Long roleId, List<Long> menuIds) {
    log.info("[菜单服务] 为角色分配菜单,roleId={}, 菜单数量={}", roleId, menuIds != null ? menuIds.size() : 0);

    // 清空旧关联
    sysRoleMenuMapper.delete(...);
    log.debug("[菜单服务] 已清空角色原有菜单关联,roleId={}", roleId);

    // 插入新关联
    if (menuIds != null && !menuIds.isEmpty()) {
        records.forEach(sysRoleMenuMapper::insert);
        log.info("[菜单服务] 角色菜单分配完成,roleId={}, 分配数量={}", roleId, menuIds.size());
    }
}

异常处理

// ✅ 业务校验失败用 warn,系统异常用 error
if (existing == null) {
    log.warn("[用户服务] 用户不存在,userId={}", userId);
    throw new ResponseStatusException(HttpStatus.NOT_FOUND, "用户不存在");
}

try {
    externalApi.call();
} catch (Exception e) {
    log.error("[支付服务] 调用支付网关失败,orderId={}", orderId, e);
    throw new PaymentException("支付失败", e);
}

Read the full file on GitHub · 118 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 118 lines · 999 tokens per session scan A da7b25e20e11

Subscribe to this mod's changes

13-code-logging-standards is a cursor rule published in the GitHub repository movebrickschi/harness-engineering-mcp (2 stars, last pushed 3mo ago), licensed MIT. It adds 999 tokens to every session, about $0.0050 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.