Add format call before logging

This commit is contained in:
IamCathal 2020-08-20 19:06:51 +01:00
parent 6bdedff457
commit 705e091593
5 changed files with 11 additions and 9 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)
}