| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package audit
- import (
- "strings"
- "udeServer/internal/response"
- )
- // ChooseLevelByBusinessCode maps a unified-response business code to a log
- // level. There is no gap for 300000-500000 like in sdf-serve because
- // udeServer always answers with HTTP 200 and encodes errors in the body.
- // Unknown codes are treated as warnings except the server-error code.
- func ChooseLevelByBusinessCode(code int64) string {
- switch code {
- case response.CodeOK:
- return "INFO"
- case response.CodeServerError:
- return "ERROR"
- default:
- // 100001 参数错误 / 100002 不存在 以及未来新增的业务错误码
- return "WARN"
- }
- }
- // SaveToDBByLogLevel decides whether a log entry is persisted: the stored
- // entry is kept when its level is at or above the configured level. An
- // empty or unrecognized configured level falls back to INFO so that the
- // audit chain keeps working before t_config is populated.
- func SaveToDBByLogLevel(configLevel, actualLevel string) bool {
- // DEBUG < INFO < WARN < ERROR
- levelOrder := map[string]int{
- "DEBUG": 1,
- "INFO": 2,
- "WARN": 3,
- "ERROR": 4,
- }
- effective := strings.ToUpper(strings.TrimSpace(configLevel))
- if _, ok := levelOrder[effective]; !ok {
- effective = "INFO"
- }
- actual, ok := levelOrder[actualLevel]
- if !ok {
- return false
- }
- return levelOrder[effective] <= actual
- }
|