npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

loki-logger-node

v1.0.2

Published

Lightweight Node.js logger for Grafana Loki — simple, fast, and easy to integrate.

Downloads

566

Readme

loki-logger-node

Lightweight Node.js logger for Grafana Loki — simple, fast, and easy to integrate.

Installation

 npm install loki-logger-node

Quick start

import { loki } from 'loki-logger-node';

const logger = loki({ name: 'my-service', stage: 'production', url: '[http://loki:3100](http://loki:3100)', pattern: 'default' });

logger.info('Bootstrap', 'Application started');

await logger.flush();

API

loki(config)

Creates or returns a logger instance.

const logger = loki({ name: 'my-service', stage: 'production', url: '[http://loki:3100](http://loki:3100)' });

Configuration

type LokiSetting = { url: string | URL; name: string; stage?: string; pattern?: string; job?: string; headers?: Record<string, string>; };

| Option | Required | Description | |---|---:|---| | url | Yes | Base Loki URL, for example http://loki:3100 or https://loki.example.com | | name | Yes | Service/application name sent as the lambda_name Loki label | | stage | No | Environment/stage sent as the env Loki label | | pattern | No | Log pattern sent as the log_pattern Loki label | | job | No | Loki job label. Defaults to lambda_logs | | headers | No | Custom HTTP headers for auth or tenancy |

HTTPS Loki endpoint

import { loki } from 'loki-logger-node';

const logger = loki({ name: 'my-service', stage: 'production', url: '[https://loki.example.com](https://loki.example.com)' });

logger.info('Bootstrap', 'Application started');

await logger.flush();

Custom headers and authentication

import { loki } from 'loki-logger-node';

const logger = loki({ name: 'my-service', stage: 'production', url: '[https://loki.example.com](https://loki.example.com)', headers: { Authorization: `Bearer ${process.env.LOKI_TOKEN}`, 'X-Scope-OrgID': 'my-tenant' } });

logger.info('Bootstrap', 'Application started');

await logger.flush();

Logger methods

logger.trace(context, message, ...params);
logger.debug(context, message, ...params);
logger.info(context, message, ...params);
logger.warn(context, message, ...params);
logger.error(context, message, ...params);
logger.fatal(context, message, ...params);

Example:

logger.info('UserService', 'User created', { userId: '123' });

Optional params are included in the JSON log body, not as Loki labels.

Sending logs

Logs are queued in memory until flushed.

await logger.flush();

For backward compatibility, execute() is also available: