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

@avanlan/logger

v0.1.5

Published

A logger for Node.js

Readme

Logger

A logger for Node.js.

Version npm NPM Downloads

NPM

Install

pnpm i @avanlan/logger

Usage

import { Logger } from '@avanlan/logger';

const logger = new Logger({
  projectName: "demo-app",
  timezone: "America/New_York",
  clean: {
    type: CleanType.NODE, // default winston
    maxFiles: 14, // default 14
    maxSize: 1024 * 1024 * 100, // default 100m
  },
  transportsFile: {
    maxsize: 1024 * 1024 * 400,
  },
  dailyRotateFile: {
    maxFiles: 14,
  },
});

logger.access.info("access log");
logger.daily.info("daily log");
logger.error.error("error log", new Error());
logger.debug.info("debug log", { a: 1 });
logger.access.info({
  time: "32m",
  method: "GET",
  url: "/",
  ip: "127.0.0.1",
  body: "hello",
  headers: { "content-type": "application/json" },
  query: { a: 1 },
});

output

[2024-12-26 23:05:18] [demo-app] [INFO]: access log
[2024-12-26 23:05:18] [demo-app] [INFO]: daily log
[2024-12-26 23:05:18] [demo-app] [ERROR]: error log Error  Error
    at Object.<anonymous> (/Users/avan/Code/personal/logger/demo.ts:21:33)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module.m._compile (/Users/avan/Code/personal/logger/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/ts-node/src/index.ts:1618:23)
    at node:internal/modules/cjs/loader:1689:10
    at Object.require.extensions.<computed> [as .ts] (/Users/avan/Code/personal/logger/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
[2024-12-26 23:05:18] [demo-app] [INFO]: debug log {"a":1}
[2024-12-26 23:05:18] [demo-app] [INFO]: 32m GET / 127.0.0.1 headers: {"content-type":"application/json"} query: {"a":1} body: "hello"

demo01

Configuration

Project

Specify the project name.

import { Logger } from '@avanlan/logger';

const logger = new Logger({
  projectName: "auth-service",
});

logger.daily.info("info log")

// output daily log
// [2024-08-08 16:37:24] [auth-service] [INFO]: info log

Timezone

The default timezone is Asia/Shanghai.

const logger = new Logger({
  timezone: "America/New_York",
});

Clean

interface CleanOptions {
  type?: CleanType;
  maxFiles?: number | string;
  maxSize?: number;
}

type: Clean type, default is CleanType.WINSTON.

maxFiles: Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. Work with CleanType.NODE. default is 14.

maxSize: Maximum size of the file after which it will rotate. unit is byte. Work with CleanType.NODE. default is 100 * 1024 * 1024(100m).

const logger = new Logger({
  clean: {
    type: CleanType.NODE,
    maxFiles: 14,
    maxSize: 1024 * 1024 * 100,
  },
});

Daily Rotate File

Work with CleanType.WINSTON.

interface DailyRotateFileConfig {
  maxSize?: stringOrNumber;
  maxFiles?: stringOrNumber;
}

maxSize: Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number.

maxFiles: Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix.

const logger = new Logger({
  dailyRotateFile: {
    maxSize: 1024 * 1024 * 400, // '400m'
    maxFiles: 14, // '14d'
  },
});

Transports File

Work with CleanType.WINSTON.

interface TransportsFileConfig {
  maxsize?: number;
  maxFiles?: number;
}
const logger = new Logger({
  transportsFile: {
    maxsize: 1024 * 1024 * 400,
    maxFiles: 14,
  },
});

Output Logger File

project
├── logger
│   ├── access
│   │   └── access.YYYY-MM-DD.log
│   ├── daily
│   │   └── daily.YYYY-MM-DD.log
│   ├── error
│   │   └── error.YYYY-MM-DD.log
│   └── debug.log

Logger Middleware

Koa

import { Logger, koaHttpLogger } from "@avanlan/logger";
import { bodyParser } from '@koa/bodyparser';

const logger = new Logger();

app.use(bodyparser());
app.use(koaHttpLogger(logger));

// output access log
// [2024-08-08 17:34:20] [main-app] [INFO]: 2ms GET / ::1 headers: {"host":"localhost:8044","user-agent":"curl/8.6.0","accept":"*/*"} query: {} body: {}

Express

import { Logger, expressHttpLogger } from "@avanlan/logger";
import bodyParser from 'body-parser';

const logger = new Logger();

app.use(bodyParser.json());
app.use(expressHttpLogger(logger));

// output access log
// [2024-08-08 17:47:55] [main-app] [INFO]: 0ms GET / ::1 headers: {"host":"localhost:5834","user-agent":"curl/8.6.0","accept":"*/*"} query: {} body: {}

Demo

demo.ts

pnpm run demo

Features

  • [x] Access log
  • [x] Daily log
  • [x] Error log
  • [x] Debug log
  • [x] Koa middleware
  • [x] Express middleware
  • [x] Console support color
  • [x] Timezone support
  • [x] Logger clear by winston
  • [x] Logger clear by node