dae/pkg/logger/logger.go

37 lines
700 B
Go

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2023, v2rayA Organization <team@v2raya.org>
*/
package logger
import (
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
func NewLogger(verbose int, disableTimestamp bool) *logrus.Logger {
log := logrus.New()
var level logrus.Level
switch verbose {
case 0:
level = logrus.WarnLevel
case 1:
level = logrus.InfoLevel
case 2:
level = logrus.DebugLevel
default:
level = logrus.TraceLevel
}
log.SetLevel(level)
log.SetFormatter(&prefixed.TextFormatter{
DisableTimestamp: disableTimestamp,
FullTimestamp: true,
TimestampFormat: "Jan 02 15:04:05",
})
return log
}