Reuse log prefix colors if we run out

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
Thomas Scholtes
2023-11-23 09:37:13 +01:00
committed by Rūdolfs Ošiņš
parent c568757675
commit b979862b08
+4 -5
View File
@@ -21,15 +21,14 @@ const availableColors: ColorName[] = [
"cyan",
];
let nextColorIndex = 0;
const assignedColors: Record<string, ColorName> = {};
export function logPrefix(label: string): string {
if (assignedColors[label] === undefined) {
const color = availableColors.pop();
if (!color) {
throw new Error("We're out of colors. 🤷");
}
const color = availableColors[nextColorIndex];
nextColorIndex = (nextColorIndex + 1) % availableColors.length;
assignedColors[label] = color;
}