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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zodyac/mono-logger-writer

v2.0.2

Published

File writing extension for Mono-logger

Readme

Writer for Mono-logger

NPM Version NPM Downloads npm bundle size Test coverage

Writer extension for Mono-logger 1.5+. Please refer to its documentation before jumping into configuring the Writer.

This effect allows you to write logs to a file with minimum configuration.

import { Logger } from '@zodyac/mono-logger';
import { WriterEffect } from '@zodyac/mono-logger-writer';

const writerEffect = new WriterEffect({
  path: 'logs',
});

const logger = new Logger("writer", {
  effect: writerEffect,
});

logger.info("Hello, World!");

// Console: 7/29/2024, 16:16:16 [INF] writer Hello, world!
//
// + file: logs/mono-logger-2024629-0.log:
// 2024-07-29T13:18:07.235Z [INF] writer Hello, world!

Changelog

Please see CHANGELOG for latest changes.

Prerequisites

  • Node.js 12+
  • Mono-logger 1.5+

Installation

Assuming you have already installed Mono-logger 1.5+:

yarn add @zodyac/mono-logger-writer

Or

npm i @zodyac/mono-logger-writer

Configuration

  • level (LogLevel) – The minimum log level to write (e.g. debug, info, warn, error, fatal). Default: debug;

  • path (string) – The directory to write logs. Default: logs;

  • filename (function) – Function to generate the filename that accepts the current date and file iterator (starts with 0) and returns a file name string;

  • transform (function) – Function to transform the log message before writing to the file. Default: undefined;

  • max_file_size (number) – The maximum file size in kilobytes before creating a new file. Default: 5 * 1024KB (~5MB);

import { Logger, type LogLevel } from '@zodyac/mono-logger';
import { WriterEffect } from '@zodyac/mono-logger-writer';

const transformer = (ts: Date, level: LogLevel, topics: string[], ...messages: any[]) => {
  const timestamp = ts.toString();
  const lvl_str = level.toUpperCase();
  return `${timestamp} [${lvl_str}] ${topics.join(':')} ${messages.join(' ')}`;
};

const writerEffect = new WriterEffect({
  level: 'info',
  path: 'logs',
  filename: (date, i) => `my-log-${date.toISOString()}-${i}.log`,
  max_file_size: 20 * 1024, // 20MB
  transform: transformer,
});

const logger = new Logger("root", {
  effect: writerEffect,
});

logger.info("Hello, World!");

// Output:
// + file: logs/my-log-2024-07-29T13:34:40.782Z-0.log
// Mon Jul 29 2024 16:35:25 GMT+0300 (Istanbul Standard time) [INFO] root Hello, World!

Size based rotation

The Writer will create a new file when the current file size exceeds the max_file_size limit. File size is provided in kilobytes. Default file size is around 5MB, which can be changed by setting the max_file_size option. If you don't want your files to be rotated, you can just pass Infinity to this field. In this case, the iterator will not have any effect.

If you stop the app and run it again with all the same configuration, iterator will be pointed to the next of the last file number. If you want to start from scratch, you can delete those files or change the filename function.

Daily rotation

By setting daily_rotation to true, you can effortlessly make the Writer create a new file every day. This is useful when you want to keep logs separated by days, not file size.

Note: This will cancel Size based rotation behavior.

How to screw things up

Common problems that can possibly happen fall into one (or more) of these categories:

  • fs cannot write to the directory because of it's access rules;

  • fs cannot write because the disk is full;

  • File is being overwritten because it happened to have same filename and path (check the path and filename function);

  • Provided max_file_size is smaller than a given record, so the file will be rotated immediately (and possibly infinitely if you dump MASSIVE amount of data in one record);

Contributing

Contribution is always welcomed! These are several points of special interest:

  • Improve test coverage (Jest);
  • Edge case exploration;
  • Stability and efficiency improvements (KISS);

You are also welcome to extend and improve Mono-logger plugin ecosystem.

License

MIT