Warning level control - with suggestion

Warning level control - with suggestion

wellsbr01wellsbr01 Posts: 2Questions: 0Answers: 0
edited March 2013 in Feature requests
If I may suggest the following code to _fnLog, to add a more flexible control of warnings and debugging:

[code]

function _fnLog( oSettings, iLevel, sMesg )
{
var sAlert = (oSettings===null) ?
"DataTables warning: "+sMesg :
"DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;

if ( iLevel === 0 )
{
if ( DataTable.ext.sErrMode == 'alert' )
{
alert( sAlert );
}
else if ( DataTable.ext.sErrMode == 'thow' )
{
throw sAlert;
}
else if ( DataTable.ext.sErrMode == 'console' )
{
console.log( sAlert );
}
else if ( DataTable.ext.sErrMode == 'mute' )
{}
return;
}
else if ( console !== undefined && console.log )
{
console.log( sAlert );
}
}

[/code]

Along with adding the usual sErrMode param on the user code:

[code]
$(function () {

$.fn.dataTableExt.sErrMode = 'mute'; //check above for other options

//.... code ....

});
[/code]

What it adds is flexibility to improve faster development when facing non-disruptive warning situations. In my case it kept issued warnings but in the end the result was a perfect DT anyway. So making it mute was just fine (it was getting really boring with the alerts and just blocking with the throw).

It is working nicely this way. Just to consider.

Thanks,

Wellington

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Good idea - like it. Bookmarked for inclusion in 1.10.

    Thanks!
    Allan
  • gdibblegdibble Posts: 1Questions: 0Answers: 0
    Good idea, wellsbr01!
    Thanks for considering this, Allan.

    I would like to add one more idea:
    A callback would also be extremely useful. This would allow the user to write their own error handler, such as a silent AJAX POST in the background to send a message to the admins/etc.
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Nice idea. I'm treading rather close to the line the size that I want 1.10 to be (in terms of bytes), so it might or might not include this - but its certainly a good idea.

    Thanks,
    Allan
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2

    Bump! Have just come across this at $WORK and would prefer a configurable error handler. According to http://stackoverflow.com/questions/11941876/correctly-suppressing-warnings-in-datatables it's only possible by changing DataTable's source... Don't mind trying to knock up a prototype if that'd be even possible.

This discussion has been closed.