mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:30:50 +00:00
Add format call before logging
This commit is contained in:
parent
6bdedff457
commit
705e091593
@ -71,7 +71,7 @@ func (el *esLogger) WriteMsg(lm *logs.LogMsg) error {
|
||||
|
||||
idx := LogDocument{
|
||||
Timestamp: lm.When.Format(time.RFC3339),
|
||||
Msg: lm.Msg,
|
||||
Msg: el.Format(lm),
|
||||
}
|
||||
|
||||
body, err := json.Marshal(idx)
|
||||
|
@ -153,7 +153,8 @@ func (w *fileLogWriter) WriteMsg(lm *LogMsg) error {
|
||||
return nil
|
||||
}
|
||||
hd, d, h := formatTimeHeader(lm.When)
|
||||
lm.Msg = string(hd) + lm.Msg + "\n"
|
||||
msg := w.Format(lm)
|
||||
msg = fmt.Sprintf("%s %s\n", string(hd), msg)
|
||||
if w.Rotate {
|
||||
w.RLock()
|
||||
if w.needRotateHourly(len(lm.Msg), h) {
|
||||
@ -180,10 +181,10 @@ func (w *fileLogWriter) WriteMsg(lm *LogMsg) error {
|
||||
}
|
||||
|
||||
w.Lock()
|
||||
_, err := w.fileWriter.Write([]byte(lm.Msg))
|
||||
_, err := w.fileWriter.Write([]byte(msg))
|
||||
if err == nil {
|
||||
w.maxLinesCurLines++
|
||||
w.maxSizeCurSize += len(lm.Msg)
|
||||
w.maxSizeCurSize += len(msg)
|
||||
}
|
||||
w.Unlock()
|
||||
return err
|
||||
|
@ -38,8 +38,7 @@ func (s *JLWriter) WriteMsg(lm *LogMsg) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
text := fmt.Sprintf("%s %s", lm.When.Format("2006-01-02 15:04:05"), lm.Msg)
|
||||
|
||||
text := fmt.Sprintf("%s %s", lm.When.Format("2006-01-02 15:04:05"), s.Format(lm))
|
||||
form := url.Values{}
|
||||
form.Add("authorName", s.AuthorName)
|
||||
form.Add("title", s.Title)
|
||||
|
@ -33,8 +33,8 @@ func (s *SLACKWriter) WriteMsg(lm *LogMsg) error {
|
||||
if lm.Level > s.Level {
|
||||
return nil
|
||||
}
|
||||
|
||||
text := fmt.Sprintf("{\"text\": \"%s %s\"}", lm.When.Format("2006-01-02 15:04:05"), lm.Msg)
|
||||
msg := s.Format(lm)
|
||||
text := fmt.Sprintf("{\"text\": \"%s %s\"}", lm.When.Format("2006-01-02 15:04:05"), msg)
|
||||
|
||||
form := url.Values{}
|
||||
form.Add("payload", text)
|
||||
|
@ -130,11 +130,13 @@ func (s *SMTPWriter) WriteMsg(lm *LogMsg) error {
|
||||
// Set up authentication information.
|
||||
auth := s.getSMTPAuth(hp[0])
|
||||
|
||||
msg := s.Format(lm)
|
||||
|
||||
// Connect to the server, authenticate, set the sender and recipient,
|
||||
// and send the email all in one step.
|
||||
contentType := "Content-Type: text/plain" + "; charset=UTF-8"
|
||||
mailmsg := []byte("To: " + strings.Join(s.RecipientAddresses, ";") + "\r\nFrom: " + s.FromAddress + "<" + s.FromAddress +
|
||||
">\r\nSubject: " + s.Subject + "\r\n" + contentType + "\r\n\r\n" + fmt.Sprintf(".%s", lm.When.Format("2006-01-02 15:04:05")) + lm.Msg)
|
||||
">\r\nSubject: " + s.Subject + "\r\n" + contentType + "\r\n\r\n" + fmt.Sprintf(".%s", lm.When.Format("2006-01-02 15:04:05")) + msg)
|
||||
|
||||
return s.sendMail(s.Host, auth, s.FromAddress, s.RecipientAddresses, mailmsg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user