dae/pkg/logger/logger.go

30 lines
601 B
Go
Raw Normal View History

2023-01-23 18:54:21 +07:00
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2022-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(logLevel string, disableTimestamp bool) *logrus.Logger {
2023-01-23 18:54:21 +07:00
log := logrus.New()
level, err := logrus.ParseLevel(logLevel)
if err != nil {
2023-01-23 18:54:21 +07:00
level = logrus.InfoLevel
}
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{
DisableTimestamp: disableTimestamp,
FullTimestamp: true,
TimestampFormat: "Jan 02 15:04:05",
2023-02-04 14:02:44 +07:00
})
2023-01-23 18:54:21 +07:00
return log
}