A small utility for producing consistent, styled logs across multiple systems. It supports glyphs, colors, names, timestamps, and inline styles, ensuring all log output looks uniform and is easy to scan.
When working in the Viapak ecosystem, it's better to have smaller packages that provide contained functionality.
With this separated architecture, logs often become messy:
This logger solves that by enforcing a shared format:
%c
styles just like console.log
2025-08-11 ⛊ Draco Connected to database
2025-08-11 ⛉ Draco Connection lost
import { logger } from "https://viapak.xyz/@utils/logger"
import { logger } from "https://viapak.xyz/@utils/logger"
class MySystem {
static isConnected = false;
static log = logger({
glyph: () => (isConnected ? "⛊" : "⛉"),
glyph_color: "white",
name: "Draco",
name_color: () => (isConnected ? "green" : "red"),
});
static async Connect() {
this.log("Connecting...");
// do stuff here
this.log("%cConnected!", "color: green; font-weight: bold;");
}
}
MySystem.log("Starting up...");
logger(props: LoggerProps) => (...data: unknown[]) => void
Name | Type | Default | Description |
---|---|---|---|
glyph |
string | () => string |
— | Single-character emoji or Unicode symbol (e.g. "⛊" ) |
glyph_color |
string | () => string |
— | Color for the glyph |
name |
string |
required | Name that identifies the logger (truncated & padded) |
name_color |
string | () => string |
— | Color for the name |
You can pass:
%c
format strings with style arguments
(these must all be in the first string for console style rules to apply)Example with inline styles:
log("%cSuccess", "color: green;", "%c(5ms)", "color: grey;");
…
%c
styles in user-supplied text are preserved%c
reset is always applied so styles don’t bleed