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

loggers-best

v1.0.2

Published

a log module for print loginfo use in TV and Mobile

Downloads

2

Readme

Loggers 使用指南

简介

为了方便在TV端和移动端能够方便的查看log信息,本模块能够在浏览器端和移动端提供一套统一的API来方便本地调试和真机调试;

安装

首先安装loggers-best模块,推荐全局安装此模块,可以开启本地log服务;

npm install -g loggers-best

会自动创建两个全局命名,分别是loggerslogs,logsloggers的别名;

使用

loggers-best支持在本地使用和服务端构建使用;

本地使用

  1. 首先在命令行中使用logs开启本地服务器,能够接受log信息,并且在浏览器页面输出log信息;
logs -o 

默认监听本机的8080端口,如果被占用可以更改监听端口; 选项:

{
    "loggers-option":{
        "-o":"是否直接打开log输出页面,默认为否",
        "-p":"服务器监听端口,默认8080",
        "-b":"-o打开log页面启用的浏览器,默认default",
        "-n":"监听页面的pageName,方便服务端构建使用,本地默认:log",
        "-h":"查看帮助信息"
    }
}

经过上面的设置,本地已经启动了一个能够接受log信息的服务器,并且启动了一个输出log信息的页面;

<URL for Logger page>: 	http://localhost:8080/console/log
<URL for Connect>:  http://ip-address:8080
<Script for CDN src>:  <script src="//g.alicdn.com/tvtaobao-assets/pushfiles/1.0.46/logger-client.js"></script>
  1. 客户端引入logger-best的客户端模块,上面<Script for CDN src>:为引入文件的CDN地址;
<script src="//g.alicdn.com/tvtaobao-assets/pushfiles/1.0.43/logger-client.js"></script>>
<script type="text/javascript">
//开启自动模式
logger.auto({
    url:"http://ip-address:8080",//本机ip地址:<URL for Connect>
    name:"log",//监听页面的pageName,需要和监听页对应;
    local:false,//默认向log页发送信息,关闭仅在本地页面调试展示log信息
    monitor:true,//打开全局监听报错,事件下一轮执行
    result:function(response) {
        console.log(response);//查看log信息的发送状态,方便调试状态
    }
});
</script>
  1. 查看log信息:首先在浏览器中打开log信息输出页,地址为<URL for Logger page>: http://localhost:8080/console/{pageName},因为loggers-best可以在服务端供多人使用,所以此处的{pageName}需要在客户端和页面地址中对应; 打开页面后,查看控制栏,log信息在此处输出,页面中仅显示当前的请求时间和请求方式;

log信息输出页

服务端使用

基本和上述方式相同,但是本地不用再次启动服务,只需要连接线上地址更改{pageName}即可,本地客户端connect的地址和线上对应;

//online
url:http://example.com:8080/console/{pageName} 
//local
logger.connect("http://example.com:8080",pageName);

客户端基本用法

  1. logger.log() 客户端的log信息基本支持现有console模块的所有用法,比如logger.warn,logger.log,logger.count等一系列W3C定义的console方法,完全如同在浏览器中使用console.log()一样,唯一的不同是将console.log改为logger.log;

  2. logger.connect(url,pageName) logger模块连接的服务端地址,比如本地启动的ip地址为http://30.22.55.100:8080/console/log,那么连接的方法如下:

logger.connect("http://30.22.55.100:8080","log");

pageName有一个默认值为log,选填; 上述地址的console只是一个命名空间,不需要在connect中写入,只需要传入hostpageName即可; 3. logger.close() log信息只建议在本地环境开启,线上生产环境需要关闭,logger提供了close()方法来关闭log信息;

  1. logger.setEnv(boolean) 如果仅仅是在模拟环境测试(浏览器模拟环境),而不是在真机上面调试,logger提供了一套统一的API,只要调用logger,setEnv(true)就可以不向远程发送log,而是在本地浏览器端直接显示log信息;

  2. logger.clearScreen() 虽然远程的log输出页面提供了清空日志的按钮,但是每次点击比较麻烦,所以提供了logger.clearScreen()的方法来清除远程页面的日志信息,在每次页面初始化的时候调用即可,别名:logger.cls();

  3. logger.postError() 真机测试的时候,然后可以使用log发送错误,但是如果碰到没有兜底的错误,那么是不会有任何提示的,logger.posetError()帮你监听全局的错误信息,并且自动发送错误到log输出页面,默认关闭;

  4. logger.getResult(callback) 如果发现logger模块输出不正常,调用此方法可以查看AJAX请求的响应信息去查看错误代码,function callback(response){print(response)}一参即为当时发送的POST请求的响应信息;

  5. logger.auto(obj) 上述一些常用的设定被封装成了一个名为auto的方法,auto里面会自动调用一些功能来简化上面的设置过程:

  • 自动调用clearScreen方法,每次页面初始化都清除上次的log;
  • 自动调用postError方法,自动监听页面的报错并发送错误;
  • 自动调用connect方法进行连接;
  • 自动调用getResult方法,传入的参数中result为Function类型,选填;

选项:auto方法传入的为object类型,参数如下:

  • url:String,对应connect的第一个参数(必填),log信息的输出地址;
  • name:String,对应connect的第二个参数,选填,默认为log;
  • local:Boolean,如果为true表明启用setEnv(true),仅在本地页面输出log信息,非真机环境使用,默认false;
  • result:Function,getResult方法的回调函数,(选填),是否查看AJAX响应信息;
  • monitor:Boolean,是否执行postError的监听,默认为:true