2023-01-23 18:54:21 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2023-02-18 17:27:28 +07:00
|
|
|
* 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
|
|
|
|
2023-02-05 13:03:34 +07:00
|
|
|
func NewLogger(logLevel string, disableTimestamp bool) *logrus.Logger {
|
2023-01-23 18:54:21 +07:00
|
|
|
log := logrus.New()
|
|
|
|
|
2023-02-05 13:03:34 +07:00
|
|
|
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{
|
2023-02-04 21:02:37 +07:00
|
|
|
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
|
|
|
|
}
|