42 lines
1.0 KiB
Markdown
42 lines
1.0 KiB
Markdown
# 交易日志系统
|
|
|
|
## 核心功能
|
|
|
|
1. **按地址/订单分离日志**
|
|
- 充值:按 `address` 命名
|
|
- 提现:按 `queueId` 命名
|
|
- 支付:按 `orderId` 命名
|
|
|
|
2. **自动日志轮转**
|
|
- 单文件超过 1MB 自动压缩为 `.log.gz`
|
|
- 后台异步压缩,不影响性能
|
|
|
|
3. **日志格式**
|
|
```
|
|
2024-01-01 12:00:00 [topup]-[待确认] | 金额: 100.000000 | 交易哈希: 0x123... | 区块高度: 12345678 | 地址: 0xabc...
|
|
```
|
|
|
|
## 使用示例
|
|
|
|
```go
|
|
// 初始化
|
|
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` 常量:
|
|
```go
|
|
const (
|
|
MaxFileSize = 1 * 1024 * 1024 // 日志轮转大小
|
|
LogDir = "logs" // 日志目录
|
|
)
|
|
```
|
|
|