A Loki Reporter for Consola
Install package:
# npm
npm install consola-loki
# yarn
yarn add consola-loki
# pnpm
pnpm install consola-loki
# bun
bun install consola-loki
Import:
// ESM
import { LokiReporter } from "consola-loki";
// CommonJS
const { LokiReporter } = require("consola-loki");
Parameter | Description | Example |
---|---|---|
baseURL |
URL for Grafana Loki | "https://logs-prod-123.grafana.net" |
interval |
The interval at which batched logs are sent in ms | 5000 |
labels |
custom labels, key-value pairs | { hostname: hostname() } |
user |
basic auth user or grafana cloud user | 123456 |
password |
basic auth password or grafana cloud token | "glc\_......" |
const consola = createConsola({
reporters: [
new LokiReporter({
baseURL: "your base url here",
user: "123456",
password: "glc_......",
labels: {
// custom global labels
hostname: hostname(), // example
},
}),
],
});
Install consola
and @nuxt/kit
.
// modules/loki.ts
import { defineNuxtModule } from "@nuxt/kit";
import { consola } from "consola";
import { LokiReporter, LokiOptions } from "consola-loki";
export default defineNuxtModule<LokiOptions>({
meta: {
name: "loki",
},
setup(options, nuxt) {
const loki = new LokiReporter(options);
consola.addReporter(loki);
},
});
// nuxt.config.ts
export default defineNuxtConfig({
// ...
loki: {
baseURL: "your base url here",
user: "123456",
password: "glc_......",
},
//...
});
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Hugely inspired by winston-loki
Made with 💛
Published under MIT License.