2019-02-23 03:17:34 +03:00
2019-02-23 03:06:30 +03:00
2019-02-23 03:04:20 +03:00
2019-02-23 03:17:34 +03:00

logrus-levelpad-formatter

Logrus (https://github.com/sirupsen/logrus) formatter allows to specify log level with padding and produces messages like:

[INFO    ][2019-02-23 03:11:36.414] Merticol service starting

parameters

  • TimestampFormat - datetime format
  • LogFormat - whole log entry format, you can specify extra params such as %lvl% (level: info, warn, error...) and %time% (timestamp previously formatted using TimestampFormat directive)
  • LevelPad - padding for %lvl% parameter, when 0 then no padding will be applied.

example configuration

import (
	log "github.com/sirupsen/logrus"
	"github.com/jar3b/logrus-levelpad-formatter"
	"os"
)

func InitLog() {
	log.SetFormatter(&levelpad.Formatter{
		TimestampFormat: "2006-01-02 15:04:05.000",
		LogFormat:       "[%lvl%][%time%] %msg%\n",
		LevelPad:        8,
	})

	log.SetOutput(os.Stdout)

	// Only log the info severity or above.
	log.SetLevel(log.InfoLevel)
}
Description
Logrus formatter with time and level with padding
Readme 30 KiB
Languages
Go 100%