Structured logging (#8673)
* Implementing structured logging * Changes to en.json to allow refactor to run. * Fixing global logger * Structured logger initalization. * Add caller. * Do some log redirection. * Auto refactor * Cleaning up l4g reference and removing dependancy. * Removing junk. * Copyright headers. * Fixing tests * Revert "Changes to en.json to allow refactor to run." This reverts commit fd8249e99bcad0231e6ea65cd77c32aae9a54026. * Fixing some auto refactor strangeness and typo. * Making keys more human readable.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2acbc77d78
Коммит
686c2fbab7
@@ -6,14 +6,15 @@ package utils
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,7 @@ type HTMLTemplateWatcher struct {
|
||||
|
||||
func NewHTMLTemplateWatcher(directory string) (*HTMLTemplateWatcher, error) {
|
||||
templatesDir, _ := FindDir(directory)
|
||||
l4g.Debug("Parsing server templates at %v", templatesDir)
|
||||
mlog.Debug(fmt.Sprintf("Parsing server templates at %v", templatesDir))
|
||||
|
||||
ret := &HTMLTemplateWatcher{
|
||||
stop: make(chan struct{}),
|
||||
@@ -57,15 +58,15 @@ func NewHTMLTemplateWatcher(directory string) (*HTMLTemplateWatcher, error) {
|
||||
return
|
||||
case event := <-watcher.Events:
|
||||
if event.Op&fsnotify.Write == fsnotify.Write {
|
||||
l4g.Info("Re-parsing templates because of modified file %v", event.Name)
|
||||
mlog.Info(fmt.Sprintf("Re-parsing templates because of modified file %v", event.Name))
|
||||
if htmlTemplates, err := template.ParseGlob(filepath.Join(templatesDir, "*.html")); err != nil {
|
||||
l4g.Error("Failed to parse templates %v", err)
|
||||
mlog.Error(fmt.Sprintf("Failed to parse templates %v", err))
|
||||
} else {
|
||||
ret.templates.Store(htmlTemplates)
|
||||
}
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
l4g.Error("Failed in directory watcher %s", err)
|
||||
mlog.Error(fmt.Sprintf("Failed in directory watcher %s", err))
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -110,7 +111,7 @@ func (t *HTMLTemplate) RenderToWriter(w io.Writer) error {
|
||||
}
|
||||
|
||||
if err := t.Templates.ExecuteTemplate(w, t.TemplateName, t); err != nil {
|
||||
l4g.Error(T("api.api.render.error"), t.TemplateName, err)
|
||||
mlog.Error(fmt.Sprintf("Error rendering template %v err=%v", t.TemplateName, err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ func escapeForHtml(arg interface{}) interface{} {
|
||||
}
|
||||
return safeArg
|
||||
default:
|
||||
l4g.Warn("Unable to escape value for HTML template %v of type %v", arg, reflect.ValueOf(arg).Type())
|
||||
mlog.Warn(fmt.Sprintf("Unable to escape value for HTML template %v of type %v", arg, reflect.ValueOf(arg).Type()))
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user