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

log-file-write

v2.2.1

Published

A lightweight, timezone-aware Node.js file logger with optional Slack notifications.

Readme

log-file-write

log-file-write is a Node.js logger focused on file-based logs with timezone support, optional Slack alerts, retention cleanup, and a simple developer API.

Requirements

  • Node.js >= 20

Installation

npm install log-file-write

Quick Start

import { SetUserOptions, Info, Error } from "log-file-write";

SetUserOptions({
  folderPath: "./logs",
  dateBasedFileNaming: true,
  logLevel: "debug",
  onlyFileLogging: true
});

await Info("Application started", "api", "bootstrap");
await Error("Database timeout", "api", "getUsers", { retry: 1 }, "database");

Modern API (recommended)

import { SetUserOptions, createLogger } from "log-file-write";

SetUserOptions({
  folderPath: "./logs",
  fileName: "application",
  dateBasedFileNaming: false,
  onlyFileLogging: true
});

const userLogger = createLogger({ serviceName: "user-service", methodName: "createUser" });
await userLogger.info("Creating user", { userId: "u-1001" });
await userLogger.error("User creation failed", { code: "DB_TIMEOUT" }, "database");

Slack Webhook Support

  1. Create an incoming webhook in your Slack workspace.
  2. Store the webhook URL in an environment variable.
  3. Pass slackWebhookUrl via SetUserOptions.
import { SetUserOptions, Error } from "log-file-write";

SetUserOptions({
  folderPath: "./logs",
  onlyFileLogging: true,
  slackWebhookUrl: process.env.SLACK_WEBHOOK_URL
});

await Error("Database timeout", "billing-service", "createInvoice", { retry: 1 }, "database");

Notes:

  • Slack is optional; file logging always works without it.
  • If webhook delivery fails, the library logs the error and continues writing to file.
  • Supported errorType values for Slack text customization: database, network, server, client, other.

API

  • SetUserOptions(options) sets runtime options and validates defaults.
  • GetUserOptions() returns the resolved options.
  • createLogger(context) creates scoped logger helpers.
  • Debug/Trace/Info/Warn/Error/Fatal/Success/Other/Log are async logging methods.

All methods support:

  1. Legacy positional arguments: Info(message, serviceName?, methodName?, errorObj?, errorType?, callback?)
  2. Object payload: Info({ message, serviceName, methodName, errorObj, errorType }, callback?)

Security Notes

  • Log fields are sanitized to reduce log-injection risks from multiline input.
  • Slack webhook failures are isolated and do not break local file logging.
  • Invalid timezone/log-level options are normalized to safe defaults.

Available Options

type TDefaultOptions = {
  timeZone: string;
  folderPath: string;
  dateBasedFileNaming: boolean;
  fileName: string;
  fileNamePrefix: string;
  fileNameSuffix: string;
  fileNameExtension: string;
  dateFormat: string;
  timeFormat: string;
  logLevel: "debug" | "prod" | "prod-trace";
  onlyFileLogging: boolean;
  slackWebhookUrl?: string;
  logsDeletePeriodInDays?: number;
};

Development

npm install
npm run lint
npm run build
npm test

Timezone Reference