MCPcopy Create free account
hub / github.com/github/gh-aw / selectNamespaceLabel

Function selectNamespaceLabel

pkg/logger/logger.go:85–101  ·  view source on GitHub ↗

selectNamespaceLabel renders the namespace label with a hash-selected style.

(namespace string)

Source from the content-addressed store, hash-verified

83
84// selectNamespaceLabel renders the namespace label with a hash-selected style.
85func selectNamespaceLabel(namespace string) string {
86 if !debugColors {
87 return namespace
88 }
89
90 // Use FNV-1a hash for consistent color assignment
91 h := fnv.New32a()
92 // hash.Hash.Write never returns an error in practice, but check to satisfy gosec G104
93 if _, err := h.Write([]byte(namespace)); err != nil {
94 // Return plain namespace (no color) if write somehow fails
95 return namespace
96 }
97 hash := h.Sum32()
98
99 // Select color from palette based on hash and render namespace with it.
100 return colorPalette[hash%uint32(len(colorPalette))].Render(namespace)
101}
102
103// Enabled returns whether this logger is enabled
104func (l *Logger) Enabled() bool {

Callers 2

TestColorSelectionFunction · 0.85
NewFunction · 0.85

Calls 2

WriteMethod · 0.80
RenderMethod · 0.65

Tested by 1

TestColorSelectionFunction · 0.68