GithubHelp home page GithubHelp logo

listar / console Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 175 KB

console 输出封装,可全局控制关闭console输出、使用console写入日志

Home Page: https://www.npmjs.com/package/console-log-star

License: Apache License 2.0

JavaScript 55.52% TypeScript 44.48%
console log

console's Introduction

console

console二次封装、console进行日志记录、console 快捷样式输出、配置一键关闭所有console输出

组件功能:

  • console原生上面所有功能
  • 组件实现配置,一键关闭所有console输出
  • 新增wlog方法进行输出控制台并可以配置这个函数回调(进行日志记录等)
  • console输出几种样式的输出log

console.csslog 使用方法如下: image.png 7种样式直接使用它们的下标,也可以自己自定义 例如下面

// csslog 使用
console.csslog("%chello%cworld", 5, 6);
console.csslog("%chello%cworld %c小明", 0, 1, 5);
console.csslog("%chello%cworld", 0, 2);
console.csslog("%chello%cworld", 0, 0);
console.csslog("%chello%cworld", 5, 6);
console.csslog("%chello world", 1);
console.csslog("%chello %cworld", 5, "background:red;color:#FFF");

使用方式

import consolelog  from "console-log-star";
let slog = new consolelog({
  consoleWriteLogFun: (...data) => {   // .wlog 输出回调函数
    console.log("------request  to do write log-------]", data);
  },
  environment: "development",  // 控制console输出  非development  console功能失效
});
// 全局声明变量 console
var console = slog.selfconsole;


// 使用
console.log(
  "%c hello world  %c error   %c 下划线   %c 紫色   %c  大盒子  %c 红色  %c value",
  console.style.markedness,
  console.style.error,
  console.style.writeLog,
  console.style.purple,
  console.style.bigBox,
  console.style.key,
  console.style.value
);
console.error("test error", "test error1");

console.warn("hello  warn");
console.trace("展示");

console.wlog("write log ", "write log 1");


// csslog 使用
console.csslog("%chello%cworld", 5, 6);
console.csslog("%chello%cworld %c 小明", 0, 1, 5);
console.csslog("%chello%cworld", 0, 2);
console.csslog("%chello%cworld", 0, 0);
console.csslog("%chello%cworld", 5, 6);
console.csslog("%chello world", 1);


//创建一个组
console.group("%c组内容输出", console.style.key);
//分组输出
console.log("我是组里面的内容1");
console.log("我是组里面的内容2");
console.log("我是组里面的内容3");
//结束
console.groupEnd();


console.time("100-elements");
for (let i = 0; i < 100; i++) {}
console.timeEnd("100-elements");

console输出支持占位符说明

  • %s - String 将用于转换除 BigInt、 Object 和 -0 外的所有值。BigInt 值将用 n 表示,而没有用户定义 toString 函数的对象使用带有选项 { depth: 0, colors: false, compact: 3 } 的 util.inspect() 进行检查。

  • %d - Number 将用于转换除 BigInt 和 Symbol 之外的所有值。

  • %i - parseInt(value, 10) 用于除 BigInt 和 Symbol 之外的所有值。

  • %f - parseFloat(value) 用于除 BigInt 和 Symbol 之外的所有值。

  • %j - JSON。如果参数包含循环引用,则替换为字符串 '[Circular]'。

  • %o - Object。具有通用 JavaScript 对象格式的对象的字符串表示形式。 类似于带有选项 { showHidden: true, showProxy: true } 的 util.inspect()。 这将显示完整对象,包括非可枚举属性和代理。

  • %O - Object。具有通用 JavaScript 对象格式的对象的字符串表示形式。 类似于 util.inspect() 但没有选项。 这将显示完整对象,不包括非可枚举属性和代理。

  • %c - CSS。该说明符会被忽略,将会跳过任何传入的 CSS。

  • %% - 单个百分号('%')。这不会消耗参数。 返回: 格式化的字符串。

官方文档

http://nodejs.cn/api/console.html

console's People

Contributors

listar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.