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

xilore-log4js

v1.1.1

Published

轻量级 TypeScript/Node 日志库,控制台/文件/上传三种输出,支持 JSON/YAML 配置

Readme

Xilore Log4js

License: MIT Node 16+

轻量级 TypeScript/Node 日志库,参考 xilore-log4j 设计,提供控制台 / 按日滚动文件 / 远程上传三种输出,支持 JSON/YAML 配置与按包/类排除。


特性

  • 门面 APIgetLogger(name)getLogger(MyClass),支持 trace / debug / info / warn / error
  • 三种输出:控制台(Print)、按日滚动写文件(Write)、远程上传(Upload),各级别可单独开关
  • 多格式配置:支持 xilore.jsonxilore.yml / xilore.yaml(需安装可选依赖 js-yaml),环境变量 log.* 可覆盖
  • 包/类排除:按名称模式排除日志,可限定生效级别
  • 控制台彩色:基于 ANSI 的级别着色,可通过配置或 NO_COLOR 关闭
  • 容器标识:自动解析 Docker/cgroup 或环境变量 CONTAINER_IDHOSTNAME
  • 宽度压缩:超长 logger 名可缩写显示

环境要求

  • Node.js 16+
  • TypeScript 5.x(仅构建时)
  • 可选:js-yaml(用于 YAML 配置)

安装

npm install xilore-log4js
# 若使用 YAML 配置
npm install js-yaml

快速开始

1. 使用 getLogger(推荐)

import { getLogger } from 'xilore-log4js';

const log = getLogger('my-app');
log.info('Hello xilore-log4js');
log.warn('Warning', new Error('demo'));

2. 按类名获取 Logger

import { getLogger } from 'xilore-log4js';

class App {
  private static log = getLogger(App);
  run() {
    App.log.info('running');
  }
}

3. 配置文件

将配置放在项目根目录(与 package.json 同级),任选其一:

| 文件 | 说明 | |-----------------|-------------------------| | xilore.json | JSON,始终可加载 | | xilore.yml / xilore.yaml | 需安装 js-yaml 时使用 |

加载优先级:xilore.json → xilore.yml,环境变量中键以 log. 开头的会覆盖已加载配置。

xilore.json 示例

{
  "log": {
    "path": ".",
    "file_prefix": "app",
    "date_format": "yyyy-MM-dd HH:mm:ss.SSS",
    "detail": {
      "trace": { "print": true, "write": false, "upload": false },
      "debug": { "print": true, "write": false, "upload": false },
      "info": { "print": true, "write": false, "upload": false },
      "warn": { "print": true, "write": true, "upload": false },
      "error": { "print": true, "write": true, "upload": true }
    },
    "upload": { "host": "", "token": "" },
    "charset": "UTF-8",
    "app_name": "my-app",
    "color": true,
    "compress_width": true,
    "exclude": [
      { "pattern": "com.third.party", "levels": ["debug", "info"] },
      "org.noise"
    ]
  }
}

xilore.yml 示例

log:
  path: .
  file_prefix: app
  date_format: "yyyy-MM-dd HH:mm:ss.SSS"
  detail:
    trace: { print: true, write: false, upload: false }
    debug: { print: true, write: false, upload: false }
    info:  { print: true, write: false, upload: false }
    warn:  { print: true, write: true, upload: false }
    error: { print: true, write: true, upload: true }
  upload: { host: "", token: "" }
  charset: UTF-8
  app_name: my-app
  color: true
  compress_width: true
  exclude:
    - pattern: com.third.party
      levels: [debug, info]
    - org.noise

配置项摘要

| 配置键 | 说明 | 默认值 | |--------|------|--------| | path | 日志文件目录 | . | | file_prefix | 日志文件名前缀(文件为 path/file_prefix+yyyy-MM-dd.log) | app | | date_format | 日期格式 | yyyy-MM-dd HH:mm:ss.SSS | | detail.{level}.print / .write / .upload | 该级别是否输出到控制台/写文件/上传 | 未配置时仅 print | | upload.host / upload.token | 上传服务地址与 token,host 为空则不上传 | 空 | | charset | 字符集 | UTF-8 | | app_name | 应用名,日志中显示为 [appName] | 空 | | color | 控制台是否彩色 | true | | compress_width | 是否压缩 logger 名宽度 | true | | exclude | 不输出日志的包或类排除项,可配 levels 限定级别 | 空 |


API

  • getLogger(name: string): XilLogger
  • getLogger(ctor: Function | { name?: string }): XilLogger
  • shutdownIfPresent(): void — 关闭 runner,等待未完成任务
  • setConfig(config: XilLogConfig | null): void — 注入配置(测试或程序化配置)

XilLogger 方法:trace, debug, info, warn, error,每个支持 (message: string)(message: string, err?: unknown)


开发与测试

npm install
npm run test        # 运行测试
npm run test:watch  # 监听模式
npm run build       # 编译

构建与发布

npm run build

发布前会自动执行 npm run test && npm run buildprepublishOnly)。

堆栈显示为 .ts 源文件:运行编译后的代码时使用 node --enable-source-maps dist/xxx.js,或安装可选依赖 source-map-support,日志中的错误堆栈会显示 TypeScript 源文件(如 demo.ts:8:32)而非编译后的 .js


许可证

MIT License