Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@171h/log

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@171h/log

封装了 console.log 日志输出

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

install

npm install @171h/log

usage

import { Logger } from '@171h/log'
const logger = new Logger("demo.ts");

const fn = () => {
  const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  const obj = { a: 1, b: 2, c: 3, d: 4, e: 5}
  logger.verbose("function name", "start...");
  logger.verbose(fn, "start...");
  logger.verbose(fn, arr);
  logger.verbose(fn, obj);
  logger.verbose(fn, ...arr);
  logger.debug(fn, "start...");
  logger.log(fn, "start...");
  logger.info(fn, "start...");
  logger.warn(fn, "start...");
  logger.error(fn, "start...");
};

fn();

// output

为每个 logger 实例设置日志等级

实例的日志等级优先级高于全局配置文件,下面这个 logger 的日志等级为 debug。

const logger = new Logger("demo.ts","debug");

为每个 logger 的不同日志等级设置前缀字符

// 默认配置

{ verbo: "✔", debug: "🐛", info: "ℹ", warn: "⚠", error: "✖" }

// 你也可以自定义配置

const logger = new Logger("demo.ts", "debug", { verbo: "✔", debug: "🐛", info: "✨", warn: "⚠", error: "✖" });

config

  • 在项目根目录创建 log.config.json 配置日志输出级别,默认 logLevelverbo 输出所有日志。
  • log.config.json 配置文件仅在 1.2.01.3.0 版本支持,且仅在 Node.js 环境可用。
日志等级

verbo < debug < info/log < warn < error < close

设置日志级别全局为 debug

大于等于 debug 级别的日志会输出 // log.config.json。log.config.json 配置文件仅在 1.2.01.3.0 版本支持,且仅在 Node.js 环境可用。

{
  "logLevel": "debug"
}
设置日志级别全局为 close

关闭所有日志输出 // log.config.json

{
  "logLevel": "close"
}

Keywords

FAQs

Package last updated on 01 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc