日志要记录什么:兼顾故障定位与敏感信息保护
让一条事件可以被解释
有效日志应该帮助回答何时发生了什么、涉及哪个对象、操作是否成功。常见字段包括事件时间、服务名称、请求标识、操作类型和结果代码。记录时间时保留时区,并确保相关服务器时钟同步,否则跨系统排查会因先后顺序错乱而受到影响。
请求标识可以把入口、业务处理和外部依赖中的相关记录连接起来。标识应具有足够区分度,但不应直接使用身份证号或访问令牌。异常记录还可以包含经过处理的错误类别与必要上下文,避免只留一句失败,也避免无选择地打印整个请求内容。
先决定哪些内容不能写入
密码、会话令牌、私钥和完整支付资料通常不应进入普通日志。对需要定位问题的个人信息,可采用遮盖或替代标识,并记录处理规则。脱敏应覆盖正常记录、异常堆栈和调试输出,不能仅在页面展示日志时才隐藏原始敏感字段。
不同日志可以设定不同保存期限。业务审计、系统故障和临时调试的用途各不相同,不宜全部无限期保留。确定期限时结合实际调查需求、容量和适用要求;到期处理也应覆盖归档副本,防止主系统删除后仍在其他位置长期保存。
确保需要时能够找到证据
集中保存有助于跨服务查询,但同时需要限制读取、下载和删除权限。对关键管理操作保留访问记录,避免任何运维人员都能随意改写全部历史。传输中断或磁盘接近容量上限时,应有明确提醒,不能等到事故发生后才发现记录缺了一整天。
定期选取一次真实业务流程,检查能否从日志重建其关键步骤,并验证时间、字段和检索条件是否一致。分析搜索引擎访问时,还应区分普通访问与经过来源验证的爬虫记录,单凭浏览器标识字符串不足以证明访问者身份。
-
WATCH: The Children's Hospital Thanksgiving Day ParadeWATCH: Viral Thanksgiving story set to be adapted for small screen2 earthquakes, aftershocks shake Los AngelesTrump admin proposes new tariffs on China, EU and 12 other trading partnersThe canceled Tesla Cybertruck is the fastest-selling used truck in AmericaTrump admin proposes new tariffs on China, EU and 12 other trading partnersMelania Trump reunites seventh group of Ukrainian and Russian children with familiesWATCH: 12-year-old soccer star turns hearing loss into inspirationS&P considers Nvidia credit downgrade over governance and ‘key man’ risksWATCH: The benefits of puppy yoga
下一篇:S&P considers Nvidia credit downgrade over governance and ‘key man’ risks
- ·Best Black Friday Toy Deals (2026): Up to 50% Off Lego, Board Games, and Toys
- ·WATCH: 'Ugly pants exchange' trend goes viral among air travelers
- ·LIVE: ABC News Live
- ·Zelenskyy urges the US to pressure Putin, calling Trump’s 'my friend' remark strange
- ·WATCH: The benefits of puppy yoga
- ·Pakistan to send troops to Saudi Arabia to bolster defenses following Houthi attacks
- ·NY Senate leader Andrea Stewart-Cousins, first woman in the role, dies at 76
- ·Sales for Biden memoir fall far short of books by Obama, Clinton
- ·AI data center boom strains construction labor across the U.S.
- ·Mike Love, founding member of The Beach Boys, dies at 85
- ·WATCH: Women around the world fight for gender equity in sumo
- ·WATCH: The Children's Hospital Thanksgiving Day Parade
- ·如何让Agent 记得住、查得准、改得对?
- ·LIVE: ABC News Live
- ·'The threat is finally real': Judge rips White House 'weaponization'
- ·2 earthquakes, aftershocks shake Los Angeles
- ·Best JBL Black Friday Deals (2026): Save on JBL Flip 7 and More
- ·2 earthquakes, aftershocks shake Los Angeles
- ·WATCH: 12-year-old soccer star turns hearing loss into inspiration
- ·'The threat is finally real': Judge rips White House 'weaponization'
- ·A month with the iPhone Duo has changed how I use my phone
- ·WATCH: The Children's Hospital Thanksgiving Day Parade
- ·WATCH: Elderly DoorDasher goes viral
- ·Mike Love, founding member of The Beach Boys, dies at 85
- ·The 7 Best Black Friday Deals on Expert-Tested Laptops (2026): Up to $470 Off
- ·Trump admin proposes new tariffs on China, EU and 12 other trading partners
- ·This new sports app is designed specifically for women’s sports
- ·Melania Trump reunites seventh group of Ukrainian and Russian children with families
- ·Pakistan to send troops to Saudi Arabia to bolster defenses following Houthi attacks
- ·Pakistan to send troops to Saudi Arabia to bolster defenses following Houthi attacks
- ·'The Traitors' ended with a $246,300 prize—here's who won and what they told us about spending it
- ·Pakistan to send troops to Saudi Arabia to bolster defenses following Houthi attacks
- ·WATCH: Elderly DoorDasher goes viral
- ·WATCH: NYPD releases new images in manhole mystery
- ·WATCH: Women around the world fight for gender equity in sumo
- ·WATCH: Australian man bikes 10,000 miles across 48 US states
