netalertx-logging-standards
GitHub定义NetAlertX后端Python代码的日志规范,包括导入方式、函数签名、日志级别使用场景、消息格式及禁止行为,确保日志记录的一致性与安全性。
Trigger Scenarios
Install
npx skills add netalertx/NetAlertX --skill netalertx-logging-standards -g -y
SKILL.md
Frontmatter
{
"name": "netalertx-logging-standards",
"description": "Logging conventions for NetAlertX backend Python code. Use this when adding, modifying, or reviewing log statements."
}
Logging Standards
Import
from logger import mylog
Never import logging directly in application code. Use mylog exclusively.
Function Signature
mylog(level, message_or_list)
message_or_list can be a plain string or a list of values — the logger joins them with spaces.
Log Levels
Levels from least to most verbose (higher number = more output):
| Level | Numeric | When to use |
|---|---|---|
"none" |
0 | Always printed regardless of user setting. Reserve for startup, fatal errors, and one-time permission checks. |
"minimal" |
1 | Important state transitions visible by default (scan start/end, plugin finish, restart). |
"verbose" |
2 | Informational progress — what the system is doing without clutter (e.g. "No changes to report"). |
"debug" |
3 | Developer-level detail — loop decisions, branch taken, counts. |
"trace" |
4 | Granular per-item tracing — individual device rows, SQL queries, raw values. |
Message Format
Prefix every message with a [Module] tag matching the file/function context:
mylog("debug", [f"[device_handling] Processing MAC: {mac}"])
mylog("verbose", ["[Scan] Scan complete — devices updated:", count])
Use f-strings inside a list element, not string concatenation:
# Correct
mylog("debug", [f"[NIC] parent={parent_mac} nic_online={nic_online}"])
# Avoid
mylog("debug", "[NIC] parent=" + parent_mac + " nic_online=" + str(nic_online))
Timestamp
mylog / file_print prepend the current local-timezone time automatically via timeNowTZ. Do not add a timestamp manually inside the message.
What NOT to Log
- Do not log raw user input without sanitization.
- Do not log full SQL query strings at
"none"or"minimal"— use"trace"at most. - Do not use
print()in server code — usemylog.file_printis an internal helper; do not call it directly.
Log File Location
Written to {logPath}/app.log (logPath from const.py → /tmp/logs at runtime). Do not hardcode this path.
Version History
- 716a41a Current 2026-08-27 19:51


