Browse Source

Log funcs worked like Printf

Vova Tkach 6 years ago
parent
commit
015e08f471
2 changed files with 9 additions and 5 deletions
  1. 4 4
      engine/wrapper/wrapper.go
  2. 5 1
      logger/logger.go

+ 4 - 4
engine/wrapper/wrapper.go

@@ -72,12 +72,12 @@ func New(l *logger.Logger, w http.ResponseWriter, r *http.Request, s *session.Se
 	}
 }
 
-func (this *Wrapper) LogAccess(msg string) {
-	this.l.Log(msg, this.R, false)
+func (this *Wrapper) LogAccess(msg string, vars ...interface{}) {
+	this.l.Log(msg, this.R, false, vars...)
 }
 
-func (this *Wrapper) LogError(msg string) {
-	this.l.Log(msg, this.R, true)
+func (this *Wrapper) LogError(msg string, vars ...interface{}) {
+	this.l.Log(msg, this.R, true, vars...)
 }
 
 func (this *Wrapper) dbReconnect() error {

+ 5 - 1
logger/logger.go

@@ -125,12 +125,16 @@ func New() *Logger {
 	return &lg
 }
 
-func (this *Logger) Log(msg string, r *http.Request, isError bool) {
+func (this *Logger) Log(msg string, r *http.Request, isError bool, vars ...interface{}) {
 	var host string = ""
 	if r != nil {
 		host = r.Host
 	}
 
+	if len(vars) > 0 {
+		msg = fmt.Sprintf(msg, vars...)
+	}
+
 	// Do not wait
 	go func() {
 		select {