交易日志系统
核心功能
-
按地址/订单分离日志
- 充值:按
address命名 - 提现:按
queueId命名 - 支付:按
orderId命名
- 充值:按
-
自动日志轮转
- 单文件超过 1MB 自动压缩为
.log.gz - 后台异步压缩,不影响性能
- 单文件超过 1MB 自动压缩为
-
日志格式
2024-01-01 12:00:00 [topup]-[待确认] | 金额: 100.000000 | 交易哈希: 0x123... | 区块高度: 12345678 | 地址: 0xabc...
使用示例
// 初始化
logger.InitTransactionLogger("logs")
defer logger.CloseTransactionLogger()
// 记录日志
logger.LogTopup(address, "待确认", amount, txHash, blockHeight)
logger.LogWithdraw(queueId, "确认", amount, from, to, txHash, blockHeight)
logger.LogPay(orderId, queueId, "确认", amount, from, to, txHash, blockHeight)
配置
修改 internal/logger/transaction_logger.go 常量:
const (
MaxFileSize = 1 * 1024 * 1024 // 日志轮转大小
LogDir = "logs" // 日志目录
)