function returns, if possible, the name of the function containing the PC.
(pc uintptr)
| 170 | |
| 171 | // function returns, if possible, the name of the function containing the PC. |
| 172 | func function(pc uintptr) string { |
| 173 | fn := runtime.FuncForPC(pc) |
| 174 | if fn == nil { |
| 175 | return dunno |
| 176 | } |
| 177 | name := fn.Name() |
| 178 | // The name includes the path name to the package, which is unnecessary |
| 179 | // since the file name is already included. Plus, it has center dots. |
| 180 | // That is, we see |
| 181 | // runtime/debug.*T·ptrmethod |
| 182 | // and want |
| 183 | // *T.ptrmethod |
| 184 | // Also the package path might contain dot (e.g. code.google.com/...), |
| 185 | // so first eliminate the path prefix |
| 186 | if lastSlash := strings.LastIndexByte(name, '/'); lastSlash >= 0 { |
| 187 | name = name[lastSlash+1:] |
| 188 | } |
| 189 | if period := strings.IndexByte(name, '.'); period >= 0 { |
| 190 | name = name[period+1:] |
| 191 | } |
| 192 | name = strings.ReplaceAll(name, "·", ".") |
| 193 | return name |
| 194 | } |
| 195 | |
| 196 | // timeFormat returns a customized time string for logger. |
| 197 | func timeFormat(t time.Time) string { |