selectNamespaceLabel renders the namespace label with a hash-selected style.
(namespace string)
| 83 | |
| 84 | // selectNamespaceLabel renders the namespace label with a hash-selected style. |
| 85 | func 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 |
| 104 | func (l *Logger) Enabled() bool { |