0.1.1Updated a month ago
# @utils/logger
## Uniform, Styled Console Logging

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.

---

## Why use it?

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:

* Different prefixes
* Inconsistent timestamps
* Random use of colors or none at all
* No clear way to visually identify which system a message came from

This logger solves that by **enforcing a shared format**:

* **Timestamp** prepended to every log
* **Glyph** (emoji or Unicode symbol) to visually mark the source/system
* **Color-coded glyphs and names** for easy scanning
* **Uniform padding and truncation** so logs align neatly
* Support for **inline `%c` styles** just like `console.log`

---

## Example Output

```
2025-08-11  ⛊ Draco       Connected to database
2025-08-11  ⛉ Draco       Connection lost
```


---

## Installation

```sh
import { logger } from "https://viapak.xyz/@utils/logger"
```

---

## Usage

```ts
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...");

```

---

## API

### `logger(props: LoggerProps) => (...data: unknown[]) => void`

#### Props

| 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                                    |

#### Log Arguments

You can pass:

* Plain strings
* Objects
* `%c` format strings with style arguments
  (these must all be **in the first string** for console style rules to apply)

Example with inline styles:

```ts
log("%cSuccess", "color: green;", "%c(5ms)", "color: grey;");
```

---

## Formatting Rules

* **Timestamp** is ISO-8601 and always grey
* **Glyph** and **name** have fixed padding for alignment
* Long names are truncated with ``
* `%c` styles in user-supplied text are preserved
* A trailing `%c` reset is always applied so styles don’t bleed