Giter Site home page Giter Site logo

virtuede / ge-log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wmz46/ge-log

0.0 0.0 0.0 40 KB

控制台日志工具类,封装console,支持输出调用事件、日志级别、调用堆栈等信息

License: MIT License

TypeScript 60.84% CSS 16.05% HTML 4.41% Vue 18.70%

ge-log's Introduction

GeLog

封装console,支持输出调用事件、日志级别、调用堆栈等信息

调用

import log from '@wmz46/go-log'
log.info('hello','world')

在控制台输出结果如下

hello world

调用时间:2022-8-12 15:4:9
日志级别:INFO
调用堆栈:at console.info (http://localhost:3000/src/utils/log.ts?t=1660287137216:176:16)
         at <anonymous>:1:9

使用方法

1.使用包管理器安装

需要有github read:packages 权限的token
在.npmrc中加入源和token

@wmz46:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken={你的token
npm install @wmz46/ge-log
# 
yarn add @wmz46/ge-log

2.浏览器直接引入

dist/index.umd.js拷贝到你的项目

<head>
  <script src='dist/index.umd.js'></script>
  <script>
    //请参考后面文档写法
    const log = GeLog
    log.info('hello world')
    ...
  </script>
</head>

3.打印日志

接口调用同console,目前支持的日志方法有debug,trace,info,log,warn,error

  import log from '@wmz46/go-log'
  log.trace('hi')
  log.debug('hi')
  log.log('hi')
  log.info('hi')
  log.warn('hi')
  log.error('hi')

4.代替默认console

如果不想修改原日志代码,可以引入后调用relaceConsole方法来代替默认console

  log.replaceConsole()

5.其他

  // 关闭详细信息,关闭后效果同默认console
  log.showDetail = false
  // 设置最低级别显示日志,枚举值如下
  // TRACE = 1,
  // DEBUG = 2,
  // LOG = 3,
  // INFO = 4,
  // WARN = 5,
  // ERROR = 6
  log.level = 3

发布到github package(作者发布备忘)

修改package.json的版本号

# 登录
npm login ----registry=https://npm.pkg.github.com
# 打包
yarn build:lib
# 发布
npm publish

ge-log's People

Contributors

wmz46 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.