mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Improve trace logging for pulls and processes (#22633)
Our trace logging is far from perfect and is difficult to follow. This PR: * Add trace logging for process manager add and remove. * Fixes an errant read file for git refs in getMergeCommit * Brings in the pullrequest `String` and `ColorFormat` methods introduced in #22568 * Adds a lot more logging in to testPR etc. Ref #22578 --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		@@ -383,6 +383,13 @@ func (cv *ColoredValue) Format(s fmt.State, c rune) {
 | 
			
		||||
	s.Write(*cv.resetBytes)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ColorFormatAsString returns the result of the ColorFormat without the color
 | 
			
		||||
func ColorFormatAsString(colorVal ColorFormatted) string {
 | 
			
		||||
	s := new(strings.Builder)
 | 
			
		||||
	_, _ = ColorFprintf(&protectedANSIWriter{w: s, mode: removeColor}, "%-v", colorVal)
 | 
			
		||||
	return s.String()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetColorBytes will allow a user to set the colorBytes of a colored value
 | 
			
		||||
func (cv *ColoredValue) SetColorBytes(colorBytes []byte) {
 | 
			
		||||
	cv.colorBytes = &colorBytes
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ import (
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/process"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type loggerMap struct {
 | 
			
		||||
@@ -285,6 +287,15 @@ func (l *LoggerAsWriter) Log(msg string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	process.Trace = func(start bool, pid process.IDType, description string, parentPID process.IDType, typ string) {
 | 
			
		||||
		if start && parentPID != "" {
 | 
			
		||||
			Log(1, TRACE, "Start %s: %s (from %s) (%s)", NewColoredValue(pid, FgHiYellow), description, NewColoredValue(parentPID, FgYellow), NewColoredValue(typ, Reset))
 | 
			
		||||
		} else if start {
 | 
			
		||||
			Log(1, TRACE, "Start %s: %s (%s)", NewColoredValue(pid, FgHiYellow), description, NewColoredValue(typ, Reset))
 | 
			
		||||
		} else {
 | 
			
		||||
			Log(1, TRACE, "Done %s: %s", NewColoredValue(pid, FgHiYellow), NewColoredValue(description, Reset))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	_, filename, _, _ := runtime.Caller(0)
 | 
			
		||||
	prefix = strings.TrimSuffix(filename, "modules/log/log.go")
 | 
			
		||||
	if prefix == filename {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user