mirror of
https://github.com/AlistGo/alist.git
synced 2025-09-15 12:58:42 +08:00
Some checks are pending
beta release / Beta Release Changelog (1.21, ubuntu-latest) (push) Waiting to run
beta release / Beta Release (md5, !(*musl*|*windows-arm64*|*android*|*freebsd*)) (push) Blocked by required conditions
beta release / Beta Release (md5-android, android-*) (push) Blocked by required conditions
beta release / Beta Release (md5-freebsd, freebsd-*) (push) Blocked by required conditions
beta release / Beta Release (md5-linux-musl, linux-!(arm*)-musl*) (push) Blocked by required conditions
beta release / Beta Release (md5-linux-musl-arm, linux-arm*-musl*) (push) Blocked by required conditions
beta release / Beta Release (md5-windows-arm64, windows-arm64) (push) Blocked by required conditions
beta release / Beta Release Desktop (push) Blocked by required conditions
build / Build (ubuntu-latest, android-arm64) (push) Waiting to run
build / Build (ubuntu-latest, darwin-amd64) (push) Waiting to run
build / Build (ubuntu-latest, darwin-arm64) (push) Waiting to run
build / Build (ubuntu-latest, linux-amd64-musl) (push) Waiting to run
build / Build (ubuntu-latest, linux-arm64-musl) (push) Waiting to run
build / Build (ubuntu-latest, windows-amd64) (push) Waiting to run
build / Build (ubuntu-latest, windows-arm64) (push) Waiting to run
release_docker / Build Binaries for Docker Release (push) Waiting to run
release_docker / Release Docker image (, latest, ) (push) Blocked by required conditions
release_docker / Release Docker image (INSTALL_ARIA2=true, aria2, suffix=-aria2,onlatest=true) (push) Blocked by required conditions
release_docker / Release Docker image (INSTALL_FFMPEG=true
INSTALL_ARIA2=true
, aio, suffix=-aio,onlatest=true) (push) Blocked by required conditions
release_docker / Release Docker image (INSTALL_FFMPEG=true, ffmpeg, suffix=-ffmpeg,onlatest=true) (push) Blocked by required conditions
- Adjust log formatter to disable colors when NO_COLOR or ALIST_NO_COLOR environment variables are set. - Reorganize formatter settings for better readability.
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/alist-org/alist/v3/cmd/flags"
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
|
"github.com/natefinch/lumberjack"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func init() {
|
|
formatter := logrus.TextFormatter{
|
|
TimestampFormat: "2006-01-02 15:04:05",
|
|
FullTimestamp: true,
|
|
}
|
|
if os.Getenv("NO_COLOR") != "" || os.Getenv("ALIST_NO_COLOR") == "1" {
|
|
formatter.DisableColors = true
|
|
} else {
|
|
formatter.ForceColors = true
|
|
formatter.EnvironmentOverrideColors = true
|
|
}
|
|
logrus.SetFormatter(&formatter)
|
|
utils.Log.SetFormatter(&formatter)
|
|
// logrus.SetLevel(logrus.DebugLevel)
|
|
}
|
|
|
|
func setLog(l *logrus.Logger) {
|
|
if flags.Debug || flags.Dev {
|
|
l.SetLevel(logrus.DebugLevel)
|
|
l.SetReportCaller(true)
|
|
} else {
|
|
l.SetLevel(logrus.InfoLevel)
|
|
l.SetReportCaller(false)
|
|
}
|
|
}
|
|
|
|
func Log() {
|
|
setLog(logrus.StandardLogger())
|
|
setLog(utils.Log)
|
|
logConfig := conf.Conf.Log
|
|
if logConfig.Enable {
|
|
var w io.Writer = &lumberjack.Logger{
|
|
Filename: logConfig.Name,
|
|
MaxSize: logConfig.MaxSize, // megabytes
|
|
MaxBackups: logConfig.MaxBackups,
|
|
MaxAge: logConfig.MaxAge, //days
|
|
Compress: logConfig.Compress, // disabled by default
|
|
}
|
|
if flags.Debug || flags.Dev || flags.LogStd {
|
|
w = io.MultiWriter(os.Stdout, w)
|
|
}
|
|
logrus.SetOutput(w)
|
|
}
|
|
log.SetOutput(logrus.StandardLogger().Out)
|
|
utils.Log.Infof("init logrus...")
|
|
}
|