2019-10-03 03:39:04 +08:00
|
|
|
var logParms = 'view=request&request=log&task=query';
|
2019-01-19 23:32:40 +08:00
|
|
|
var logReq = new Request.JSON( {url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: logResponse} );
|
2011-06-21 17:19:10 +08:00
|
|
|
var logTimer = undefined;
|
|
|
|
var logTable = undefined;
|
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
var logCodes = {
|
|
|
|
'0': 'INF',
|
|
|
|
'-1': 'WAR',
|
|
|
|
'-2': 'ERR',
|
|
|
|
'-3': 'FAT',
|
|
|
|
'-4': 'PNC',
|
|
|
|
};
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2017-07-06 23:42:35 +08:00
|
|
|
var minSampleTime = 2000;
|
2011-06-21 17:19:10 +08:00
|
|
|
var maxSampleTime = 16000;
|
|
|
|
var minLogTime = 0;
|
|
|
|
var maxLogTime = 0;
|
|
|
|
var logCount = 0;
|
|
|
|
var maxLogFetch = 100;
|
|
|
|
var filter = {};
|
|
|
|
var logTimeout = maxSampleTime;
|
|
|
|
var firstLoad = true;
|
|
|
|
var initialDisplayLimit = 200;
|
|
|
|
var sortReversed = false;
|
2017-03-18 15:00:51 +08:00
|
|
|
var filterFields = ['Component', 'ServerId', 'Pid', 'Level', 'File', 'Line'];
|
2011-06-21 17:19:10 +08:00
|
|
|
var options = {};
|
|
|
|
|
2019-06-04 22:32:29 +08:00
|
|
|
function escapeHtml(unsafe) {
|
|
|
|
return unsafe
|
2019-06-07 01:40:00 +08:00
|
|
|
.replace(/&/g, "&")
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">")
|
|
|
|
.replace(/"/g, """)
|
2019-06-04 22:32:29 +08:00
|
|
|
.replace(/'/g, "'");
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function buildFetchParms( parms ) {
|
|
|
|
var fetchParms = logParms+'&limit='+maxLogFetch;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( parms ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
fetchParms += '&'+parms;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
Object.each(filter,
|
|
|
|
function( value, key ) {
|
|
|
|
fetchParms += '&filter['+key+']='+value;
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
);
|
2018-05-17 02:17:57 +08:00
|
|
|
return fetchParms;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function fetchNextLogs() {
|
|
|
|
logReq.send( buildFetchParms( 'minTime='+maxLogTime ) );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function fetchPrevLogs() {
|
|
|
|
logReq.send( buildFetchParms( 'maxTime='+minLogTime ) );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function logResponse( respObj ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( logTimer ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
logTimer = clearTimeout( logTimer );
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
if ( respObj.result == 'Ok' ) {
|
|
|
|
if ( respObj.logs.length > 0 ) {
|
|
|
|
logTimeout = minSampleTime;
|
|
|
|
logCount += respObj.logs.length;
|
|
|
|
try {
|
|
|
|
respObj.logs.each(
|
|
|
|
function( log ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( ( !maxLogTime ) || ( log.TimeKey > maxLogTime ) ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
maxLogTime = log.TimeKey;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
|
|
|
if ( ( !minLogTime ) || ( log.TimeKey < minLogTime ) ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
minLogTime = log.TimeKey;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2019-02-10 10:43:55 +08:00
|
|
|
|
2019-06-04 22:32:29 +08:00
|
|
|
var row = logTable.push([
|
|
|
|
{content: log.DateTime, properties: {style: 'white-space: nowrap'}},
|
|
|
|
log.Component, log.Server, log.Pid, log.Code,
|
|
|
|
escapeHtml(log.Message),
|
|
|
|
escapeHtml(log.File),
|
|
|
|
log.Line
|
|
|
|
]);
|
2019-01-18 23:00:55 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
delete log.Message;
|
|
|
|
row.tr.store( 'log', log );
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( log.Level <= -3 ) {
|
|
|
|
row.tr.addClass( 'log-fat' );
|
|
|
|
} else if ( log.Level <= -2 ) {
|
|
|
|
row.tr.addClass( 'log-err' );
|
|
|
|
} else if ( log.Level <= -1 ) {
|
|
|
|
row.tr.addClass( 'log-war' );
|
|
|
|
} else if ( log.Level > 0 ) {
|
|
|
|
row.tr.addClass( 'log-dbg' );
|
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
if ( !firstLoad ) {
|
|
|
|
var color = document.defaultView.getComputedStyle(row.tr, null).getPropertyValue('color');
|
|
|
|
var colorParts = color.match(/^rgb.*\((\d+),\s*(\d+),\s*(\d+)/);
|
|
|
|
rowOrigColor = '#' + parseInt(colorParts[1]).toString(16) + parseInt(colorParts[2]).toString(16) + parseInt(colorParts[3]).toString(16);
|
2017-06-16 01:02:54 +08:00
|
|
|
//new Fx.Tween( row.tr, { duration: 10000, transition: Fx.Transitions.Sine } ).start( 'color', '#6495ED', rowOrigColor );
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
);
|
2018-09-10 04:36:09 +08:00
|
|
|
if ( typeof(respObj.options) == 'object' ) {
|
|
|
|
$j.each( respObj.options,
|
2019-01-19 23:32:40 +08:00
|
|
|
function( field ) {
|
|
|
|
if ( options[field] ) {
|
|
|
|
options[field] = Object.assign(options[field], respObj.options[field]);
|
|
|
|
} else {
|
|
|
|
options[field] = respObj.options[field];
|
|
|
|
}
|
|
|
|
}
|
2018-09-10 04:36:09 +08:00
|
|
|
);
|
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
updateFilterSelectors();
|
|
|
|
$('lastUpdate').set('text', respObj.updated);
|
|
|
|
$('logState').set('text', respObj.state);
|
|
|
|
$('logState').removeClass('ok');
|
|
|
|
$('logState').removeClass('alert');
|
|
|
|
$('logState').removeClass('alarm');
|
|
|
|
$('logState').addClass(respObj.state);
|
|
|
|
$('totalLogs').set('text', respObj.total);
|
|
|
|
$('availLogs').set('text', respObj.available);
|
|
|
|
$('displayLogs').set('text', logCount);
|
|
|
|
if ( firstLoad ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( logCount < displayLimit ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
fetchPrevLogs();
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
logTable.reSort();
|
2019-01-19 23:32:40 +08:00
|
|
|
} catch ( e ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
console.error( e );
|
|
|
|
}
|
|
|
|
logTimeout /= 2;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( logTimeout < minSampleTime ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
logTimeout = minSampleTime;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
} else {
|
|
|
|
firstLoad = false;
|
|
|
|
logTimeout *= 2;
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( logTimeout > maxSampleTime ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
logTimeout = maxSampleTime;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2017-07-06 23:42:35 +08:00
|
|
|
} // end logs.length > 0
|
|
|
|
} // end if result == Ok
|
2017-05-19 01:50:56 +08:00
|
|
|
logTimer = fetchNextLogs.delay( logTimeout );
|
2017-03-18 15:00:51 +08:00
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function refreshLog() {
|
|
|
|
options = {};
|
2019-10-03 03:39:04 +08:00
|
|
|
$j('#logTable tbody').empty();
|
2017-05-19 01:50:56 +08:00
|
|
|
firstLoad = true;
|
|
|
|
maxLogTime = 0;
|
|
|
|
minLogTime = 0;
|
|
|
|
logCount = 0;
|
|
|
|
logTimeout = maxSampleTime;
|
|
|
|
displayLimit = initialDisplayLimit;
|
|
|
|
fetchNextLogs();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function expandLog() {
|
|
|
|
displayLimit += maxLogFetch;
|
|
|
|
fetchPrevLogs();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 03:39:04 +08:00
|
|
|
function clearResponse() {
|
|
|
|
refreshLog();
|
|
|
|
}
|
|
|
|
function clearError() {
|
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
function clearLog() {
|
|
|
|
logReq.cancel();
|
2019-10-03 03:39:04 +08:00
|
|
|
|
|
|
|
var clearParms = 'view=request&request=log&task=delete';
|
2019-12-21 05:11:38 +08:00
|
|
|
var clearReq = new Request.JSON({url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: clearResponse});
|
|
|
|
var tbody = $(logTable).getElement('tbody');
|
|
|
|
var rows = tbody.getElements('tr');
|
2020-04-06 23:59:27 +08:00
|
|
|
if ( rows && rows.length ) {
|
2019-10-03 03:39:04 +08:00
|
|
|
var minTime = rows[0].getElement('td').get('text');
|
|
|
|
clearParms += "&minTime="+encodeURIComponent(minTime);
|
|
|
|
var maxTime = rows[rows.length-1].getElement('td').get('text');
|
|
|
|
clearParms += "&maxTime="+encodeURIComponent(maxTime);
|
|
|
|
}
|
|
|
|
var form = $('logForm');
|
|
|
|
clearReq.send(clearParms+"&"+form.toQueryString());
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function filterLog() {
|
|
|
|
filter = {};
|
|
|
|
filterFields.each(
|
|
|
|
function( field ) {
|
|
|
|
var selector = $('filter['+field+']');
|
2019-12-21 05:11:38 +08:00
|
|
|
if ( !selector ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
if ( window.console && window.console.log ) {
|
2019-10-03 03:39:04 +08:00
|
|
|
window.console.log('No selector found for ' + field);
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
|
|
|
return;
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
var value = selector.get('value');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( value ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
filter[field] = value;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
);
|
2017-05-19 01:50:56 +08:00
|
|
|
refreshLog();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function resetLog() {
|
|
|
|
filter = {};
|
|
|
|
refreshLog();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var exportFormValidator;
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function exportLog() {
|
|
|
|
exportFormValidator.reset();
|
|
|
|
$('exportLog').overlayShow();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function exportResponse( response ) {
|
|
|
|
$('exportLog').unspin();
|
|
|
|
if ( response.result == 'Ok' ) {
|
|
|
|
window.location.replace( thisUrl+'?view=request&request=log&task=download&key='+response.key+'&format='+response.format );
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function exportFail( request ) {
|
|
|
|
$('exportLog').unspin();
|
2019-12-21 05:11:38 +08:00
|
|
|
$('exportErrorText').set('text', request.status+' / '+request.statusText);
|
2017-05-19 01:50:56 +08:00
|
|
|
$('exportError').show();
|
2019-12-21 05:11:38 +08:00
|
|
|
Error('Export request failed: '+request.status+' / '+request.statusText);
|
2011-06-24 06:33:07 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function exportRequest() {
|
|
|
|
var form = $('exportForm');
|
2019-10-03 03:39:04 +08:00
|
|
|
$('exportErrorText').set('text', '');
|
2017-05-19 01:50:56 +08:00
|
|
|
$('exportError').hide();
|
|
|
|
if ( form.validate() ) {
|
|
|
|
var exportParms = "view=request&request=log&task=export";
|
2019-12-21 05:11:38 +08:00
|
|
|
var exportReq = new Request.JSON({url: thisUrl, method: 'post', link: 'cancel', onSuccess: exportResponse, onFailure: exportFail});
|
2017-05-19 01:50:56 +08:00
|
|
|
var selection = form.getElement('input[name=selector]:checked').get('value');
|
|
|
|
if ( selection == 'filter' || selection == 'current' ) {
|
|
|
|
$$('#filters select').each(
|
|
|
|
function( select ) {
|
|
|
|
exportParms += "&"+select.get('id')+"="+select.get('value');
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
);
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
|
|
|
if ( selection == 'current' ) {
|
|
|
|
var tbody = $(logTable).getElement( 'tbody' );
|
|
|
|
var rows = tbody.getElements( 'tr' );
|
|
|
|
if ( rows ) {
|
|
|
|
var minTime = rows[0].getElement('td').get('text');
|
|
|
|
exportParms += "&minTime="+encodeURIComponent(minTime);
|
|
|
|
var maxTime = rows[rows.length-1].getElement('td').get('text');
|
|
|
|
exportParms += "&maxTime="+encodeURIComponent(maxTime);
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2019-12-21 05:11:38 +08:00
|
|
|
exportReq.send(exportParms+"&"+form.toQueryString());
|
2017-05-19 01:50:56 +08:00
|
|
|
$('exportLog').spin();
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function updateFilterSelectors() {
|
|
|
|
Object.each(options,
|
2019-01-19 23:32:40 +08:00
|
|
|
function( values, key ) {
|
|
|
|
var selector = $('filter['+key+']');
|
2019-12-21 05:11:38 +08:00
|
|
|
if ( !selector ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( window.console && window.console.log ) {
|
2019-10-03 03:39:04 +08:00
|
|
|
window.console.log('No selector found for ' + key);
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
selector.options.length = 1;
|
|
|
|
if ( key == 'Level' ) {
|
|
|
|
Object.each(values,
|
|
|
|
function( value, label ) {
|
|
|
|
selector.options[selector.options.length] = new Option(value, label);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else if ( key == 'ServerId' ) {
|
|
|
|
Object.each(values,
|
|
|
|
function( value, label ) {
|
|
|
|
selector.options[selector.options.length] = new Option(value, label);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Object.each(values,
|
|
|
|
function( value, label ) {
|
|
|
|
selector.options[selector.options.length] = new Option(value, label);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( filter[key] ) {
|
|
|
|
selector.set('value', filter[key]);
|
|
|
|
}
|
2018-09-10 04:36:09 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function initPage() {
|
|
|
|
displayLimit = initialDisplayLimit;
|
2019-01-19 23:32:40 +08:00
|
|
|
for ( var i = 1; i <= 9; i++ ) {
|
2017-05-19 01:50:56 +08:00
|
|
|
logCodes[''+i] = 'DB'+i;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
logTable = new HtmlTable( $('logTable'),
|
|
|
|
{
|
2018-05-17 02:17:57 +08:00
|
|
|
zebra: true,
|
|
|
|
sortable: true,
|
|
|
|
sortReverse: true
|
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
);
|
2017-05-19 01:50:56 +08:00
|
|
|
logTable.addEvent( 'sort', function( tbody, index ) {
|
2019-10-03 03:39:04 +08:00
|
|
|
var header = tbody.getParent('table').getElement('thead');
|
|
|
|
var columns = header.getElement('tr').getElements('th');
|
2019-01-19 23:32:40 +08:00
|
|
|
var column = columns[index];
|
2019-10-03 03:39:04 +08:00
|
|
|
sortReversed = column.hasClass('table-th-sort-rev');
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( logCount > displayLimit ) {
|
2019-10-03 03:39:04 +08:00
|
|
|
var rows = tbody.getElements('tr');
|
2019-01-19 23:32:40 +08:00
|
|
|
var startIndex;
|
|
|
|
if ( sortReversed ) {
|
|
|
|
startIndex = displayLimit;
|
|
|
|
} else {
|
|
|
|
startIndex = 0;
|
|
|
|
}
|
|
|
|
for ( var i = startIndex; logCount > displayLimit; i++ ) {
|
|
|
|
rows[i].destroy();
|
|
|
|
logCount--;
|
|
|
|
}
|
|
|
|
$('displayLogs').set('text', logCount);
|
|
|
|
} // end if loCount > displayLimit
|
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
);
|
|
|
|
exportFormValidator = new Form.Validator.Inline($('exportForm'), {
|
|
|
|
useTitles: true,
|
2019-10-03 03:39:04 +08:00
|
|
|
warningPrefix: '',
|
|
|
|
errorPrefix: ''
|
2017-05-19 01:50:56 +08:00
|
|
|
});
|
2019-10-03 03:39:04 +08:00
|
|
|
new Asset.css('css/spinner.css');
|
2017-05-19 01:50:56 +08:00
|
|
|
fetchNextLogs();
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kick everything off
|
2019-10-03 03:39:04 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', initPage);
|