0.0.5 • Published 1 year ago

consola-loki v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

consola-loki

npm version npm downloads

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:

ParameterDescriptionExample
baseURLURL for Grafana Loki"https://logs-prod-123.grafana.net"
intervalThe interval at which batched logs are sent in ms5000
labelscustom labels, key-value pairs{ hostname: hostname() }
userbasic auth user or grafana cloud user123456
passwordbasic 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.

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago