dae/pkg/logger/logger.go

36 lines
637 B
Go
Raw Normal View History

2023-01-23 18:54:21 +07:00
/*
* SPDX-License-Identifier: AGPL-3.0-only
2023-01-28 12:56:06 +07:00
* Copyright (c) since 2023, v2rayA Organization <team@v2raya.org>
2023-01-23 18:54:21 +07:00
*/
package logger
2023-02-04 14:02:44 +07:00
import (
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
2023-01-23 18:54:21 +07:00
func NewLogger(verbose int) *logrus.Logger {
log := logrus.New()
var level logrus.Level
switch verbose {
case 0:
level = logrus.WarnLevel
case 1:
level = logrus.InfoLevel
2023-01-28 14:59:53 +07:00
case 2:
level = logrus.DebugLevel
2023-01-23 18:54:21 +07:00
default:
level = logrus.TraceLevel
}
2023-01-27 01:10:27 +07:00
2023-01-23 18:54:21 +07:00
log.SetLevel(level)
2023-02-04 14:02:44 +07:00
log.SetFormatter(&prefixed.TextFormatter{
FullTimestamp: true,
TimestampFormat: "Jan 02 15:04:05",
})
2023-01-23 18:54:21 +07:00
return log
}