@@ -125,15 +125,19 @@ func EventFormatTextMessage(mode *WriterMode, event *Event, msgFormat string, ms
125125 buf = append (buf , resetBytes ... )
126126 }
127127 }
128- if flags & (Lshortfile | Llongfile ) != 0 {
128+ if flags & (Lshortfile | Llongfile ) != 0 && event . Filename != "" {
129129 if mode .Colorize {
130130 buf = append (buf , fgGreenBytes ... )
131131 }
132132 file := event .Filename
133133 if flags & Lmedfile == Lmedfile {
134- startIndex := len (file ) - 20
135- if startIndex > 0 {
136- file = "..." + file [startIndex :]
134+ fileLen := len (file )
135+ const softLimit = 20
136+ if fileLen > softLimit {
137+ slashIndex := strings .LastIndexByte (file [:fileLen - softLimit ], '/' )
138+ if slashIndex != - 1 {
139+ file = ".../" + file [slashIndex + 1 :]
140+ }
137141 }
138142 } else if flags & Lshortfile != 0 {
139143 startIndex := strings .LastIndexByte (file , '/' )
@@ -157,14 +161,22 @@ func EventFormatTextMessage(mode *WriterMode, event *Event, msgFormat string, ms
157161 if mode .Colorize {
158162 buf = append (buf , fgGreenBytes ... )
159163 }
160- funcname := event .Caller
164+ funcName := event .Caller
165+ shortFuncName := funcName
161166 if flags & Lshortfuncname != 0 {
162- lastIndex := strings .LastIndexByte (funcname , '.' )
163- if lastIndex > 0 && len (funcname ) > lastIndex + 1 {
164- funcname = funcname [lastIndex + 1 :]
167+ // funcName = "code.gitea.io/gitea/modules/foo/bar.MyFunc.func1.2()"
168+ slashPos := strings .LastIndexByte (funcName , '/' )
169+ dotPos := strings .IndexByte (funcName [slashPos + 1 :], '.' )
170+ if dotPos > 0 {
171+ // shortFuncName = "MyFunc.func1.2()"
172+ shortFuncName = funcName [slashPos + 1 + dotPos + 1 :]
173+ if strings .Contains (shortFuncName , "." ) {
174+ shortFuncName = strings .ReplaceAll (shortFuncName , ".func" , "." )
175+ }
165176 }
177+ funcName = shortFuncName
166178 }
167- buf = append (buf , funcname ... )
179+ buf = append (buf , funcName ... )
168180 if mode .Colorize {
169181 buf = append (buf , resetBytes ... )
170182 }
0 commit comments