This commit is contained in:
@@ -164,7 +164,7 @@ func EventFormatTextMessage(mode *WriterMode, event *Event, msgFormat string, ms
|
||||
funcName := event.Caller
|
||||
shortFuncName := funcName
|
||||
if flags&Lshortfuncname != 0 {
|
||||
// funcName = "code.gitea.io/gitea/modules/foo/bar.MyFunc.func1.2()"
|
||||
// funcName = "gitea.dev/modules/foo/bar.MyFunc.func1.2()"
|
||||
slashPos := strings.LastIndexByte(funcName, '/')
|
||||
dotPos := strings.IndexByte(funcName[slashPos+1:], '.')
|
||||
if dotPos > 0 {
|
||||
|
||||
@@ -6,7 +6,7 @@ package log
|
||||
import (
|
||||
"os"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"gitea.dev/modules/util"
|
||||
)
|
||||
|
||||
type WriterConsoleOption struct {
|
||||
|
||||
@@ -6,8 +6,8 @@ package log
|
||||
import (
|
||||
"io"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/modules/util/rotatingfilewriter"
|
||||
)
|
||||
|
||||
type WriterFileOption struct {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"gitea.dev/modules/json"
|
||||
)
|
||||
|
||||
// These flags define which text to prefix to each log entry generated
|
||||
|
||||
@@ -6,7 +6,7 @@ package log
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"gitea.dev/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
|
||||
"gitea.dev/modules/process"
|
||||
"gitea.dev/modules/util/rotatingfilewriter"
|
||||
)
|
||||
|
||||
var projectPackagePrefix string
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"gitea.dev/modules/json"
|
||||
)
|
||||
|
||||
// Level is the level of the logger
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"gitea.dev/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -54,10 +54,6 @@ func ErrorWithSkip(skip int, format string, v ...any) {
|
||||
Log(skip+1, ERROR, format, v...)
|
||||
}
|
||||
|
||||
func Critical(format string, v ...any) {
|
||||
Log(1, ERROR, format, v...)
|
||||
}
|
||||
|
||||
var OsExiter = os.Exit
|
||||
|
||||
// Fatal records fatal log and exit process
|
||||
@@ -75,12 +71,23 @@ func IsLoggerEnabled(name string) bool {
|
||||
return GetManager().GetLogger(name).IsEnabled()
|
||||
}
|
||||
|
||||
func SetConsoleLogger(loggerName, writerName string, level Level) {
|
||||
func SetupStderrLogger(loggerName, writerName string, level Level) {
|
||||
writer := NewEventWriterConsole(writerName, WriterMode{
|
||||
Level: level,
|
||||
Flags: FlagsFromBits(LstdFlags),
|
||||
Colorize: CanColorStdout,
|
||||
WriterOption: WriterConsoleOption{},
|
||||
Level: level,
|
||||
Flags: FlagsFromBits(LstdFlags),
|
||||
Colorize: CanColorStderr,
|
||||
|
||||
// For most CLI commands, it's better to use Stderr as log output:
|
||||
// this logger is installed early (app.Before), before subcommands like "dump" redirect logging to stderr.
|
||||
// If Stdout, early log output (e.g.: warning during config loading) goes to stdout
|
||||
// and corrupts any command that writes data to stdout (e.g. "gitea dump --file -").
|
||||
//
|
||||
// It is inconsistent with the web server's default console logger from config
|
||||
// (which will be initialized later and use Stdout by default), but there is no other way at the moment:
|
||||
// many existing users depend on such behavior to collect web logs (e.g. fail2ban).
|
||||
//
|
||||
// Maybe need to refactor the logger system again in the future.
|
||||
WriterOption: WriterConsoleOption{Stderr: true},
|
||||
})
|
||||
GetManager().GetLogger(loggerName).ReplaceAllWriters(writer)
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/util"
|
||||
)
|
||||
|
||||
type LoggerImpl struct {
|
||||
|
||||
Reference in New Issue
Block a user