yjsnlog Controller and Wrapper for logging JavaScript errors to the server

  1. Requirements
  2. Usage
  3. Resources

Log JavaScript errors in the Client Browser to the Server.

The goal is to allow the collection of JavaScript errors in the Client's Browser so that bugs can be fixed pro-actively and without need for specific interventions from the end user.

Requirements

  • Works with Yii 1.1.17 (probably with lower versions too).
  • Uses http://jsnlog.com/ (included with the extension).

Usage

  1. Add a Logger Controller.

You can use the included controller by creating "LoggerController.php" in the controllers directory like this:

<?php
Yii::import('ext.YJSNLog.LoggerController',true);

That controller adds the messages to the YiiLog.

Then you have to initiate the logging by calling the widget. Here is a sample utility function:

/**
 * Adds javascript debug to the HTML output.
 */
    public static function setupJavaScriptDebug($reportUrl='logger/jsn') {
    	Yii::import('ext.YJSNLog.*');
    	Yii::app()->getController()
    	    ->widget('YJSNLog',array(
    		'handleOnError'=>true,
    		'ajaxAppenderOptions'=>array(
    		    'url'=>Yii::app()->createUrl($reportUrl),
    		    'disallow'=>implode(
    			'|',
    			array(
    			    // Parts of expressions that should not be logged.
    			    '"url":"https://maps.gstatic.com/maps-api-v3'
    			    ,'at Zba'
    			    ,'document.querySelector..title...textContent'
    			    ,"'removeChild'"
    			    ,'//tags.bkrtx.com/js/bk-coretag.js'
    			    ,'"msg":"Exception!","errorMsg":"Script error.","url":"","line number":0'
    			)
    		   )
    	    ),
        ));
    }

Resources

1 0
1 follower
87 downloads
Yii Version: 1.1
License: MIT
Category: Logging
Developed by: le_top
Created on: Aug 4, 2016
Last updated: 7 years ago

Downloads

show all

Related Extensions