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

mw-log4ts

v1.4.7

Published

Log4Ts Credit By G.S.C.

Downloads

12

Readme

Log4Ts

Log4Ts 日志管理 in pure typescript。提供统一的日志管理以及简单的过滤功能。

v1.4.7
by LviatYi

阅读该文档时,推荐安装以下字体:

若出现乱码,其为 Nerd Font 的特殊字符,不影响段落语义。

Functional ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠐⠒⠒⠒⠒⠚⠛⣿⡟⠄⠄⢠⠄⠄⠄⡄⠄⠄⣠⡶⠶⣶⠶⠶⠂⣠⣶⣶⠂⠄⣸⡿⠄⠄⢀⣿⠇⠄⣰⡿⣠⡾⠋⠄⣼⡟⠄⣠⡾⠋⣾⠏⠄⢰⣿⠁⠄⠄⣾⡏⠄⠠⠿⠿⠋⠠⠶⠶⠿⠶⠾⠋⠄⠽⠟⠄⠄⠄⠃⠄⠄⣼⣿⣤⡤⠤⠤⠤⠤⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄

它旨在提供如下便利:

  • [x] 因时制宜 使用 DebugLevels 对日志进行分级控制。
  • [x] 恰如其分 提供过滤功能,与 gitignore 配合实现客制化的日志选项。
  • [x] 主次分明 对多行日志进行标题与缩进控制,以提升可读性。
  • [x] 客随主便 永不抛出异常,即使传入了错误的参数或 MessageGetter。
  • [x] 蓄盈待竭 将日志行打包为块处理。
  • [x] 抽丝剥茧 自动识别 Error 并暴露堆栈信息。

Example ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠐⠒⠒⠒⠒⠚⠛⣿⡟⠄⠄⢠⠄⠄⠄⡄⠄⠄⣠⡶⠶⣶⠶⠶⠂⣠⣶⣶⠂⠄⣸⡿⠄⠄⢀⣿⠇⠄⣰⡿⣠⡾⠋⠄⣼⡟⠄⣠⡾⠋⣾⠏⠄⢰⣿⠁⠄⠄⣾⡏⠄⠠⠿⠿⠋⠠⠶⠶⠿⠶⠾⠋⠄⠽⠟⠄⠄⠄⠃⠄⠄⣼⣿⣤⡤⠤⠤⠤⠤⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄

Config

支持 自定义配置 以对你的环境进行私有的日志输出配置。以下是操作步骤:

  1. 在该文件夹下建立 Log4TsSelfConfig.ts 文件

    /project/JavaScripts/depends/log4ts/Log4TsSelfConfig.ts

  2. 在该文件中编写配置

    // recommend to add this file in gitignore
    // Log4TsSelfConfig.ts
       
    import Log4Ts, { Log4TsConfig } from "./Log4Ts";
       
    Log4Ts.setConfig(
        new Log4TsConfig()
            .addBlackList("IDontWantThis"),
    );
  3. 将文件在 gitignore 中忽略

    # Custom
    Log4TsSelfConfig.ts

Chunk

使用 setChunkHandlersetChunkSize 配置日志缓存块的处理方式与大小。

// recommend to add this file in gitignore

import Log4Ts, {Log4TsConfig} from "./Log4Ts";

Log4Ts.setConfig(
       new Log4TsConfig()
               .setChunkHandler((chunk) => {
                   console.log(chunk);
               })
               .setChunkSize() // set size 1
               .setChunkSize(50), // 当未调用过 setChunkSize 时,使用默认值 50
);

由于某些运行时 TypeScript 版本限制,无法使用 TypeScript5.2 的 Dispose 特性。建议在生命周期结束后,手动调用最后一次未满的 Chunk 处理。

import Log4Ts from "./Log4Ts";

Log4Ts.forceHandleChunk();

Snippet ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠐⠒⠒⠒⠒⠚⠛⣿⡟⠄⠄⢠⠄⠄⠄⡄⠄⠄⣠⡶⠶⣶⠶⠶⠂⣠⣶⣶⠂⠄⣸⡿⠄⠄⢀⣿⠇⠄⣰⡿⣠⡾⠋⠄⣼⡟⠄⣠⡾⠋⣾⠏⠄⢰⣿⠁⠄⠄⣾⡏⠄⠠⠿⠿⠋⠠⠶⠶⠿⠶⠾⠋⠄⠽⠟⠄⠄⠄⠃⠄⠄⣼⣿⣤⡤⠤⠤⠤⠤⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄

Snippet 是一种由 IDE 支持的代码片段,允许通过简写来快速输入重复的代码模式。

如,以下配置允许你仅输入 llog 即可生成包含所在类名或文件名的 Log4Ts 的日志输出代码。

Visual Studio Code

{
    "Log4Ts": {
        "prefix": "llog",
        "body": [
            "Log4Ts.${1:log}(${TM_FILENAME_BASE} ,`${2:message}`)"
        ],
        "description": "Log with Log4Ts"
    }
}

JetBrains

jetBrains-snippet

Log4Ts.$LOGMETHOD$($CLASSNAME$, `$END$`)