consola-loki
v0.0.5
Published
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
Downloads
208
Readme
consola-loki
A Loki Reporter for Consola
Usage
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");
Options:
| 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\_......"
|
Example:
const consola = createConsola({
reporters: [
new LokiReporter({
baseURL: "your base url here",
user: "123456",
password: "glc_......",
labels: {
// custom global labels
hostname: hostname(), // example
},
}),
],
});
With Nuxt:
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_......",
},
//...
});
Development
- 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
Special Thanks
Hugely inspired by winston-loki
License
Made with 💛
Published under MIT License.