github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/utils/log.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"bytes"
     8  	"io"
     9  	"io/ioutil"
    10  
    11  	l4g "github.com/alecthomas/log4go"
    12  )
    13  
    14  // InfoReader logs the content of the io.Reader and returns a new io.Reader
    15  // with the same content as the received io.Reader.
    16  // If you pass reader by reference, it won't be re-created unless the loglevel
    17  // includes Debug.
    18  // If an error is returned, the reader is consumed an cannot be read again.
    19  func InfoReader(reader io.Reader, message string) (io.Reader, error) {
    20  	var err error
    21  	l4g.Info(func() string {
    22  		content, err := ioutil.ReadAll(reader)
    23  		if err != nil {
    24  			return ""
    25  		}
    26  
    27  		reader = bytes.NewReader(content)
    28  
    29  		return message + string(content)
    30  	})
    31  
    32  	return reader, err
    33  }