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

awesome-loggerjs

v1.0.6

Published

Lightweight, extensible, zero dependencies JavaScript logger.

Downloads

15

Readme

Logger

Lightweight, extensible, zero dependencies JavaScript logger.

日志输出举例

const LogLevel = {
    DEBUG: 0,
    0: "DEBUG",
    INFO: 1,
    1: "INFO",
    WARN: 2,
    2: "WARN",
    ERROR: 3,
    3: "ERROR",
    FATAL: 4,
    4: "FATAL",
    /**
     * 不展示任何日志
     */
    NONE: 1000,
    1000: "NONE"
}
  1. 设置日志级别为 DEBUG ,则显示 DEBUG 级别以上日志(含DEBUG)。
  2. 设置日志界别为 ERROR ,则显示 ERROR、FATAL。

Usage

AMD and CommonJS module


// <script src="${path}/dist/index.umd.js"></script>

const logger = new Logger.Logger({
    level: Logger.LogLevel.DEBUG,
    isSetLocalLog: false,
    /**
     * getStdout 暴露出函数,可用于服务上传日志。
     */
    getStdout: (level, ...logs) => {
        // 可以通过 level 判断输出日志级别
        if(Logger.LogLevel.ERROR <= level) {
            // 只输出 ERROR 级别以上日志
            console.log("stdout log ->", level, ...logs)
        }
    }
);


logger.debug("[login]", { id: 123, arr: [1, 3, 5, '000', 6] });
logger.info("stdout info log!", [{ obj: 111, name: "allen" }, [1, 2, 4, 5]]);
logger.warn("stdout warn log!");
logger.error("stdout error log!");
logger.fatal("stdout fatal log!");

npm


// npm i awesome-loggerjs

import { Logger, LogLevel } from "awesome-loggerjs"
const logger = new Logger({
  level: LogLevel.DEBUG, // 设置日志级别
  getStdout: (level, ...logs) => {
      // 可以通过 level 判断输出日志级别
      if(LogLevel.ERROR <= level) {
          // 只输出 ERROR 级别以上日志
          console.log("stdout log ->", level, ...logs)
      }
  }
)

logger.debug("[login]", { id: 123, arr: [1, 3, 5, '000', 6] });
logger.info("stdout info log!", [{ obj: 111, name: "allen" }, [1, 2, 4, 5]]);
logger.warn("stdout warn log!");
logger.error("stdout error log!");
logger.fatal("stdout fatal log!");