一个记录到我们后端的JavaScript前端日志记录系统? [英] A JavaScript frontend logging system that logs to our backend?

查看:739
本文介绍了一个记录到我们后端的JavaScript前端日志记录系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们为服务器端服务建立了日志记录系统。具体来说,我们的Django项目大量使用Python日志记录模块,因此调用 logger.info() logger.warn() logger.error()被我们的集中记录系统接收。



我会就像我们前端的等价物,我有一些想法:


  1. 会有某种自定义日志记录对象通过JavaScript公开,通过XmlHttpRequest将消息发送到后端。


  2. 我希望客户端具有相同的日志记录级别: debug info 警告错误


  3. 当我们在本地开发(调试模式)时,我希望将这些日志消息记录到浏览器/ Firebug控制台通过 console.log()


  4. 在生产中, debug 消息应该完全删除。


  5. 我记得有办法捕获所有未捕获的JavaSc ript例外,所以这些应记录在错误级别。


  6. 我们已经在使用< a href =http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html =nofollow noreferrer> Google Analytics事件跟踪,它对任何事情都很好我们创建的系统以某种方式与之结合。


这是个好主意吗?你会怎么做?是否有现有的解决方案?



(FWIW,我们在前端使用jQuery。)



更新:简化问题: https://stackoverflow.com / questions / 1423267 / are-there-any-logging-frameworks-for-javascript

解决方案

首先,我编写并维护 log4javascript ,所以我事先声明了我的兴趣。我每天都在工作中使用它,所以我作为用户有一些经验。以下是我将如何处理您的问题,特别是与log4javascript有关的问题:


  1. 使用log4javascript的 AjaxAppender ;


  2. debug info warning 错误,以及跟踪致命;


  3. 使用 BrowserConsoleAppender 登录FireBug或本机浏览器控制台;


  4. 如果你不喜欢要从生产代码中删除所有调试日志记录调用,您可以调整记录器的阈值(使用 log.setLevel(log4javascript.Level.ERROR),例如,这将禁止优先级小于 ERROR 的所有日志调用。如果要取消所有日志记录调用,可以在生产中放入存储版本的log4javascript 使用 window.onerror 。类似于 window.onerror = function(msg,file,line){log.error(错误在+ file +on line+ line +:+ msg); }


  5. 我不确定您希望如何配合Google Analytics。 log4javascript对它没有特别的支持。



We have an established logging system for our server-side services. Specifically, our Django project makes heavy use of the Python logging module, so call calls to logger.info(), logger.warn() and logger.error() get picked up by our centralized logging system.

I would like an equivalent on our frontend, and I've got a few ideas:

  1. There would be some sort of custom logging object exposed via JavaScript that would send messages to backend via an XmlHttpRequest.

  2. I'd like to have equivalent logging levels on the client-side: debug, info, warning and error.

  3. When we're developing locally (debug mode), I'd like those logging messages to be logged to the browser/Firebug console via console.log().

  4. In production, debug messages should be dropped completely.

  5. I recall seeing a way to capture all uncaught JavaScript exceptions, so these should be logged at the error level.

  6. We're already using Google Analytics event tracking, and it'd be nice for whatever system we create to tie into that somehow.

Is this a good idea? How would you do this? Are there existing solutions?

(FWIW, we're using jQuery on the frontend.)

Update: Simplified question here: https://stackoverflow.com/questions/1423267/are-there-any-logging-frameworks-for-javascript

解决方案

First, I wrote and maintain log4javascript, so I'm declaring my interest up front. I also use it every day in my work, so I have some experience of it as a user. Here's how I would deal with your questions, specifically relating to log4javascript:

  1. Use log4javascript's AjaxAppender for server logging;

  2. debug, info, warning and error are all supported, as well as trace and fatal;

  3. Use a BrowserConsoleAppender to log to FireBug or the native browser console;

  4. If you don't want to remove all debug logging calls from you production code, you can either adjust your logger's threshold (using log.setLevel(log4javascript.Level.ERROR), for example, which will suppress all log calls with priority less than ERROR). If you want to suppress all logging calls, you can drop in a stub version of log4javascript in your production code.

  5. You'll need to write a bit of code to do this using window.onerror. Something like window.onerror = function(msg, file, line) { log.error("Error in " + file + " on line " + line + ": " + msg); }

  6. I'm not sure how you want to tie in with Google Analytics. log4javascript has no particular support for it.

这篇关于一个记录到我们后端的JavaScript前端日志记录系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆