| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package logger
- import (
- "fmt"
- "strings"
- )
- //
- //******************third.log文件
- //日志格式举例:2018-01-01 10:25:57:404|https://oep.songguo7.com/ebike-op-oep/ebike/get_bike_qr_code|200|1313|5|0|traceid
- // HTTP & HTTPS & thrift & ws等协议请求
- // 格式:【时间(精确到毫秒)】|【请求url】|【http状态码】|【响应时间(毫秒为单位)】|【response大小(若有则打印,若无默认为0)】|【exception状态0:正常 1:异常】|【traceid唯一ID,如果接入nginx可以从nginx 的http header中获取】
- //#{Time}: 时间
- //#{Url}: 完整url地址
- //#{StatusCode}: http状态码
- //#{CostTime}: 响应时间
- //#{ResBodyNum}: response大小
- //#{IsException}: 异常状态0:正常 1:异常
- //#{TraceId}: trace_id
- //日志分割逻辑
- //接天分割
- //task.log # 当前的日志
- //task.log.2019-08-03 # 2019-08-03 号的日志
- ///data/log/{project_name}/task.log.2019-08-03 #日志存放目录
- var (
- ThirdLog = func(url string, statusCode int, costTime int64, resBodyNum int64, traceId string) {
- var isException int
- if statusCode != 200 {
- isException = 1
- }
- if !strings.HasPrefix(url, "http") {
- url = "http://" + url
- }
- err := _fileLogWriter.Thirdlog().thirdOutput(fmt.Sprintf("|%s|%d|%d|%d|%d|%s",
- url,
- statusCode,
- costTime,
- resBodyNum,
- isException,
- traceId,
- ))
- if err != nil {
- consoleLogger.Errorf("write third log to file fail, err: %s", err.Error())
- }
- }
- )
|