吉安网站建设公司,火鸟门户系统,wordpress 相册调用,专业网站建设推荐本篇文章来自一个需求#xff0c;前端websocket会收到各种消息#xff0c;但是调试的时候#xff0c;我希望把websoekt推送过来的消息都保存到一个文件里#xff0c;如果出问题的时候#xff0c;我可以把这些消息的日志文件提交给后端开发区分析错误。但是在浏览器里… 本篇文章来自一个需求前端websocket会收到各种消息但是调试的时候我希望把websoekt推送过来的消息都保存到一个文件里如果出问题的时候我可以把这些消息的日志文件提交给后端开发区分析错误。但是在浏览器里js一般是不能写文件的。鼠标另存为的方法也是不太好因为会保存所有的console.log的输出。于是终于找到这个debugout.js。 debugout.js的原理是将所有日志序列化后保存到一个变量里。当然这个变量不会无限大因为默认的最大日志限制是2500行这个是可配置的。另外debugout.js也支持在localStorage里存储日志的。 debugout.js 一般来说可以使用打开console面板然后右键save是可以将console.log输出的信息另存为log文件的。但是这就把所有的日志都包含进来了如何只保存我想要的日志呢 调试输出从您的日志中生成可以搜索时间戳下载等的文本文件。 参见下面的一些例子。 Debugout的log接受任何类型的对象包括函数。 Debugout不是一个猴子补丁而是一个单独的记录类你使用而不是控制台。 调试的一些亮点 在运行时或任何时间获取整个日志或尾部搜索并切片日志更好地了解可选时间戳的使用模式在一个地方切换实时日志记录console.log可选地将输出存储在window.localStorage中并在每个会话中持续添加到同一个日志可选地将日志上限为X个最新行以限制内存消耗下图是使用downloadLog方法下载的日志文件。 官方提供的demo示例欢迎试玩。http://inorganik.github.io/de... 使用 在脚本顶部的全局命名空间中创建一个新的调试对象并使用debugout的日志方法替换所有控制台日志方法 var bugout new debugout();// instead of console.log(some object or string)
bugout.log(some object or string); API log() -像console.log(), 但是会自动存储getLog() - 返回所有日志tail(numLines) - 返回尾部执行行日志默认100行search(string) - 搜索日志getSlice(start, numLines) - 日志切割downloadLog() - 下载日志clear() - 清空日志determineType() - 一个更细粒度的typeof为您提供方便可选配置 ···// log in real time (forwards to console.log)self.realTimeLoggingOn true; // insert a timestamp in front of each logself.useTimestamps false; // store the output using window.localStorage() and continuously add to the same log each sessionself.useLocalStorage false; // set to false after youre done debugging to avoid the log eating up memoryself.recordLogs true; // to avoid the log eating up potentially endless memoryself.autoTrim true; // if autoTrim is true, this many most recent lines are savedself.maxLines 2500; // how many lines tail() will retrieveself.tailNumLines 100; // filename of log downloaded with downloadLog()self.logFilename log.txt;// max recursion depth for logged objectsself.maxDepth 25;··· 项目地址 https://github.com/inorganik/... 另外 我自己也模仿debugout.js写了一个日志保存的项目该项目可以在ie10及以上下载日志。debugout.js在ie浏览器上下载日志的方式是有问题的。项目地址https://github.com/wangduandu...