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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@emooa/logger

v0.0.8

Published

A simple logger to work with Nodejs.

Downloads

34

Readme

Logger 日志

@emooa/logger 是一个与 Nodejs 一起使用的简单记录器,通过 TS 开发,设计为支持多种传输的简单日志库。

Installation

npm install @emooa/logger
// or
yarn add @emooa/logger

Usage

@emooa/logger 支持 import 导入和 require 导入两种模式。

CommonJS

const Logger = require("@emooa/logger");

ESM

import Logger from "@emooa/logger";

简单例子:

const Logger = require("@emooa/logger");

const logger = new Logger({
  category: "My Project",
});

logger.log("The color is grey!");
logger.info("The color is green!");
logger.warn("The color is yellow!");
logger.error("The color is red!");
logger.debug("The color is cyan!");

将使用彩色布局输出日志信息。

[2023-12-17 12:56:25] [LOG] My Project - The color is grey!
[2023-12-17 12:56:25] [INFO] My Project - The color is green!
[2023-12-17 12:56:25] [WARN] My Project - The color is yellow!
[2023-12-17 12:56:25] [ERROR] My Project - The color is red!
[2023-12-17 12:56:25] [DEBUG] My Project - The color is cyan!

Appender 例子:

  • 目前支持4种 Appender 附加器类型,分别是 stdout, console, stderr, 和 file.

  • 当 Appender 附加器类型为File时,支持文件自定义配置日志格式。

  • 支持 3 种布局类型,即 messagebasicpattern。默认为basic,输出格式为%[[%d] [%p]%] %m

  • 当布局类型为正则时,它允许您定义任何您想要的任何格式。

const Logger = require("@emooa/logger");

const logger = new Logger({
  category: "My Project",
  appenders: [
    {
      type: "stdout", // "console" | "stderr" | "stdout" | "file"
      colour: true,
      layout: {
        type: "pattern", // message, basic, pattern,
        pattern: "%[[%d] [%p]%] %m",
      },
    },
    {
      type: "file",
      colour: false,
      file: {
        filename: "log/emooa-logger.log",
        options: {
          keepFileExt: true,
        },
      },
      layout: {
        type: "basic",
      },
    },
  ],
});

logger.log("The color is grey!");
logger.info("The color is green!");
logger.warn("The color is yellow!");
logger.error("The color is red!");
logger.debug("The color is cyan!");

更多例子见: Examples.

API

Appender

| 参数 | 类型 | 默认值 | 定义 | | --- | --- | --- | --- | | type | consolestderrstdoutfile (必填) | null | 日志输出类型。 | | colour | boolean | true | 是否输出彩色日志。 | | layout | Layout (必填) | { type: 'basic' } | appemder布局,支持多种日志输出格式。 | | file | File (当 type=file 时必填) | { filename: 'logs/emooa-logger.log' } | 文件附加器,具有基于文件大小或日期的可配置日志滚动。 |

Layout

Appender 布局,支持多种日志输出格式。

| 参数 | 类型 | 默认值 | 定义 | | --- | --- | --- | --- | | type | basicmessagepattern (必填) | basic | basic [time] [logLevel] category - message message 简单消息 pattern 一种特殊类型,允许您定义所需的任何格式。 | | pattern | string (当附加器 type 为 pattern 时必填) | %[[%d] [%p]%] %m | 一种特殊类型,允许您定义任何您想要的格式。 |

File

文件附加器,具有基于文件大小或日期的可配置日志滚动,阅读更多

  • filename - 默认为logs/emooa-logger.log。
  • maxSize - 默认为 0 - 触发翻转的大小(以字节为单位)。如果未指定或为 0,则不会发生日志滚动。
  • options
    • encoding - 默认为“utf8”。
    • mode - 默认为 0o600(请参阅 node.js 文件模式)。
    • flags -默认为 'a'(请参阅​​node.js 文件标志)。
    • compress - 默认为 false - 使用 gzip 压缩备份文件(备份文件将具有 .gz 扩展名)。
    • keepFileExt - 默认为 false - 旋转日志文件时保留文件扩展名(file.log 变为 file.1.log 而不是 file.log.1)。
    • fileNameSep - 滚动时的文件名分隔符。例如:abc.log.1 或 abc.1.log (keepFileExt)。

License

MIT Licensed
Copyright (c) 2023 Emooa