| 171 | } |
| 172 | |
| 173 | func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { |
| 174 | if i, s := bl.Status(); i != WORK { |
| 175 | return errors.New("The current status is " + s) |
| 176 | } |
| 177 | |
| 178 | lm := new(logMsg) |
| 179 | lm.level = loglevel |
| 180 | if bl.enableFuncCallDepth { |
| 181 | _, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) |
| 182 | if !ok { |
| 183 | file = "???" |
| 184 | line = 0 |
| 185 | } |
| 186 | _, filename := path.Split(file) |
| 187 | lm.msg = fmt.Sprintf("[%s:%d] %s", filename, line, msg) |
| 188 | } else { |
| 189 | lm.msg = msg |
| 190 | } |
| 191 | |
| 192 | if lm.level <= bl.stealLevel { |
| 193 | bl.stealOne(lm) |
| 194 | } |
| 195 | |
| 196 | if bl.asynchronous { |
| 197 | bl.msg <- lm |
| 198 | } else { |
| 199 | bl.lock.RLock() |
| 200 | defer bl.lock.RUnlock() |
| 201 | for name, l := range bl.outputs { |
| 202 | err := l.WriteMsg(lm.msg, lm.level) |
| 203 | if err != nil { |
| 204 | fmt.Println("unable to WriteMsg to adapter:", name, err) |
| 205 | return err |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | // Set log message level. |
| 213 | // |