Linter and Drone config fixes, code linting.

This commit is contained in:
2021-11-20 23:06:40 +05:00
parent 9c045e9fd3
commit d5fcc5cef9
22 changed files with 152 additions and 146 deletions

View File

@@ -1,13 +1,11 @@
package logger
import (
// stdlib
"fmt"
"os"
"strings"
"time"
// other
"github.com/rs/zerolog"
)
@@ -17,6 +15,7 @@ var (
)
// Initialize initializes zerolog with proper formatting and log level.
// nolint:forbidigo
func Initialize() {
// Check environment for logger level.
// Defaulting to INFO.
@@ -45,27 +44,28 @@ func Initialize() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
// nolint:exhaustivestruct
output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339}
output.FormatLevel = func(i interface{}) string {
output.FormatLevel = func(lvlRaw interface{}) string {
var v string
if ii, ok := i.(string); ok {
ii = strings.ToUpper(ii)
switch ii {
if lvl, ok := lvlRaw.(string); ok {
lvl = strings.ToUpper(lvl)
switch lvl {
case "DEBUG":
v = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl)
case "ERROR":
v = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl)
case "FATAL":
v = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl)
case "INFO":
v = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl)
case "PANIC":
v = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl)
case "WARN":
v = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", ii)
v = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl)
default:
v = ii
v = lvl
}
}