Comment se débarrasser des espaces entre les journaux lors de l'utilisation du package 'logrus'
Blue Bot:
J'ai donc commencé à utiliser «logrus». Je l'ai mis dans mon propre package logger qui ressemble à ceci:
package logger
import(
log "github.com/Sirupsen/logrus"
)
func InitLogger() {
var textFormatter = new(log.TextFormatter)
textFormatter.TimestampFormat = "2006-01-02 15:04:05"
textFormatter.ForceColors = true
textFormatter.FullTimestamp = true
log.SetFormatter(textFormatter)
}
func Printf(format string, v ...interface{}) {
log.Printf(format, v...)
}
func Fatalf(format string, v ...interface{}) {
log.Fatalf(format, v...)
}
func Panicf(format string, v ...interface{}) {
log.Panicf(format, v...)
}
func Debugf(format string, v ...interface{}) {
log.Debugf(format, v...)
(cela va comme ça pour toutes les fonctions de log de logrus, ne voyez pas l'intérêt de les coller toutes ici, mais vous voyez l'idée ...)
Utilisez-le dans mon projet comme:
import(
log "logger"
)
Et tout est pêche, sauf les journaux imprimés avec des interlignes entre eux:
INFO[2016-04-16 17:32:51] pathPrefix: /app/
pathValue: {js ./app/}
INFO[2016-04-16 17:32:51] pathPrefix: /node_modules/
pathValue: {js ./node_modules/}
INFO[2016-04-16 17:32:51] Listening for HTTP on tcp (0.0.0.0:8080)
INFO[2016-04-16 17:38:02] Starting HomeHandler
INFO[2016-04-16 17:38:02] GET / Index 4.769735ms
INFO[2016-04-16 17:38:02] Starting AuthCheckHandler
ERRO[2016-04-16 17:38:02] Failed getting cookie from user: http: named cookie not present
INFO[2016-04-16 17:38:02] GET /auth AuthCheckHandler 67.79µs
INFO[2016-04-16 17:38:02] Starting AuthCheckHandler
ERRO[2016-04-16 17:38:02] Failed getting cookie from user: http: named cookie not present
INFO[2016-04-16 17:38:02] GET /auth AuthCheckHandler 82.195µs
Comment puis-je me débarrasser de ces espaces? Je n'ai trouvé aucune solution dans la documentation / google ni ici, donc je suppose que c'est quelque chose de très idiot qui me manque ...
Merci
Stantonnet:
On dirait que vous passez des nouvelles lignes lorsque vous passez votre formatage de chaîne.
func main() {
x := 0
logger.InitLogger()
logger.Printf("%s", "TEST1")
logger.Printf("%s", "TEST2")
if x == 0 {
logger.Printf("%s", "TEST3")
logger.Printf("%s", "TEST4")
logger.Printf("%s", "TEST5")
}
}
Retour:
go run main.go
INFO[2016-04-16 12:40:30] TEST1
INFO[2016-04-16 12:40:30] TEST2
INFO[2016-04-16 12:40:30] TEST3
INFO[2016-04-16 12:40:30] TEST4
INFO[2016-04-16 12:40:30] TEST5