Skip to content

Commit

Permalink
logg/slog: add Remove/ResetKnownPathMapping, Remove/ResetKnownPathReg…
Browse files Browse the repository at this point in the history
…expMapping, ...
  • Loading branch information
hedzr committed Nov 15, 2024
1 parent d8beb80 commit e30d1ec
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions slog/cmn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func AddCodeHostingProviders(provider, repl string) { codeHostingProvidersMap[pr
// - pwd -> "." (current directory -> '.', that means any abs-path will be converted to rel-path)
func AddKnownPathMapping(pathname, repl string) { knownPathMap[pathname] = repl }

// RemoveKnownPathMapping _
func RemoveKnownPathMapping(pathname string) {
delete(knownPathMap, pathname)
}

// ResetKnownPathMapping _
func ResetKnownPathMapping() {
clear(knownPathMap) // just for go1.21+
}

// AddKnownPathRegexpMapping adds regexp pattern, repl pair to reduce the called filepath width.
func AddKnownPathRegexpMapping(pathnameRegexpExpr, repl string) {
knownPathRegexpMap = append(knownPathRegexpMap, regRepl{
Expand All @@ -32,6 +42,21 @@ func AddKnownPathRegexpMapping(pathnameRegexpExpr, repl string) {
})
}

// RemoveKnownPathRegexpMapping _
func RemoveKnownPathRegexpMapping(pathnameRegexpExpr string) {
for i, vv := range knownPathRegexpMap {
if vv.expr.String() == pathnameRegexpExpr {
knownPathRegexpMap = append(knownPathRegexpMap[:i], knownPathRegexpMap[i+1:]...)
return
}
}
}

// ResetKnownPathRegexpMapping clears all rules in knownPathRegexpMap.
func ResetKnownPathRegexpMapping() {
knownPathRegexpMap = nil
}

// SetLevelOutputWidth sets how many characters of level string should
// be formatted and output to logging lines.
//
Expand Down

0 comments on commit e30d1ec

Please sign in to comment.