| 145 | } |
| 146 | |
| 147 | func (sLog *smartIDELogStruct) Error(err interface{}, headers ...string) (reErr error) { |
| 148 | |
| 149 | if err == nil { |
| 150 | return nil |
| 151 | } |
| 152 | |
| 153 | // 基本的信息 |
| 154 | contents := headers |
| 155 | contents = append(contents, fmt.Sprint(err)) |
| 156 | |
| 157 | // 前缀 |
| 158 | prefix := getPrefix(zapcore.ErrorLevel) |
| 159 | contents = RemoveDuplicatesAndEmpty(contents) |
| 160 | |
| 161 | // 堆栈 |
| 162 | stack := string(debug.Stack()) |
| 163 | fullContents := append(contents, stack) |
| 164 | fullContents = RemoveDuplicatesAndEmpty(fullContents) |
| 165 | if sLog.Ws_id != "" { |
| 166 | ch <- struct{}{} |
| 167 | WG.Add(1) |
| 168 | go func() { |
| 169 | SendAndReceive("business", "workspaceLog", "", "", model.WorkspaceLog{ |
| 170 | Title: "", |
| 171 | ParentId: sLog.ParentId, |
| 172 | Content: strings.Join(fullContents, ";"), |
| 173 | Ws_id: sLog.Ws_id, |
| 174 | Level: 4, |
| 175 | Type: 1, |
| 176 | StartAt: time.Now(), |
| 177 | EndAt: time.Now(), |
| 178 | }) |
| 179 | defer WG.Done() |
| 180 | <-ch |
| 181 | }() |
| 182 | } |
| 183 | fullContents = entryptionKeys(fullContents) // 加密密钥 |
| 184 | |
| 185 | // 调试模式时向控制台输出堆栈 |
| 186 | if isDebugLevel { |
| 187 | fmt.Println(prefix, strings.Join(fullContents, "; ")) |
| 188 | } else { |
| 189 | fmt.Println(prefix, strings.Join(contents, "; ")) |
| 190 | } |
| 191 | |
| 192 | // 日志中一定输出完整的日志 |
| 193 | sugarLogger.Error(fullContents) |
| 194 | os.Exit(1) |
| 195 | |
| 196 | return nil |
| 197 | } |
| 198 | |
| 199 | func (sLog *smartIDELogStruct) Fatal(fatal interface{}, headers ...string) { |
| 200 | if fatal != nil { |