OutPut outputs log file, the original method
(level int, s string)
| 195 | |
| 196 | // OutPut outputs log file, the original method |
| 197 | func (log *ZinxLoggerCore) OutPut(level int, s string) error { |
| 198 | now := time.Now() // get current time |
| 199 | var file string // file name of the current caller of the log interface |
| 200 | var line int // line number of the executed code |
| 201 | log.mu.Lock() |
| 202 | defer log.mu.Unlock() |
| 203 | |
| 204 | if log.flag&(BitShortFile|BitLongFile) != 0 { |
| 205 | log.mu.Unlock() |
| 206 | var ok bool |
| 207 | // get the file name and line number of the current caller |
| 208 | _, file, line, ok = runtime.Caller(log.calldDepth) |
| 209 | if !ok { |
| 210 | file = "unknown-file" |
| 211 | line = 0 |
| 212 | } |
| 213 | log.mu.Lock() |
| 214 | } |
| 215 | |
| 216 | // reset buffer |
| 217 | log.buf.Reset() |
| 218 | // write log header |
| 219 | log.formatHeader(now, file, line, level) |
| 220 | // write log content |
| 221 | log.buf.WriteString(s) |
| 222 | // add line break |
| 223 | if len(s) > 0 && s[len(s)-1] != '\n' { |
| 224 | log.buf.WriteByte('\n') |
| 225 | } |
| 226 | |
| 227 | var err error |
| 228 | if log.fw == nil { |
| 229 | // if log file is not set, output to console |
| 230 | _, _ = os.Stderr.Write(log.buf.Bytes()) |
| 231 | } else { |
| 232 | // write the filled buffer to IO output |
| 233 | _, err = log.fw.Write(log.buf.Bytes()) |
| 234 | } |
| 235 | |
| 236 | if log.onLogHook != nil { |
| 237 | log.onLogHook(log.buf.Bytes()) |
| 238 | } |
| 239 | return err |
| 240 | } |
| 241 | |
| 242 | func (log *ZinxLoggerCore) verifyLogIsolation(logLevel int) bool { |
| 243 | return log.isolationLevel > logLevel |