303 lines
4.4 KiB
JavaScript
303 lines
4.4 KiB
JavaScript
|
|
|
||
|
|
import tools from '../unify/tools.js';
|
||
|
|
|
||
|
|
import document from '../unify/document.js';
|
||
|
|
|
||
|
|
import deepclone from '../unify/clonedeep.js';
|
||
|
|
|
||
|
|
class Console{
|
||
|
|
|
||
|
|
objects = new Array();
|
||
|
|
|
||
|
|
currentObject = false;
|
||
|
|
|
||
|
|
filename = false;
|
||
|
|
|
||
|
|
enabled = false;
|
||
|
|
|
||
|
|
enabledPaths = new Array();
|
||
|
|
|
||
|
|
rows = new Array();
|
||
|
|
|
||
|
|
tableName = false;
|
||
|
|
|
||
|
|
maxChars = new Array( 0,0,0,0,0,0 );
|
||
|
|
|
||
|
|
padding = 4;
|
||
|
|
|
||
|
|
|
||
|
|
setFilename( filename ){
|
||
|
|
|
||
|
|
this.filename = filename;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
createNameObject( parameter ) {
|
||
|
|
|
||
|
|
if( !parameter ) {
|
||
|
|
|
||
|
|
return false;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if( typeof parameter == "string") {
|
||
|
|
|
||
|
|
return parameter;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
var object = {};
|
||
|
|
|
||
|
|
object[ tools.getClassName( parameter ) ] = parameter;
|
||
|
|
|
||
|
|
return object;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
getObjectByPath( objectA ) {
|
||
|
|
|
||
|
|
var objects = this.objects;
|
||
|
|
|
||
|
|
for( var c = 0; c<objects.length; c++ ) {
|
||
|
|
|
||
|
|
var objectB = objects[c];
|
||
|
|
|
||
|
|
if( objectA.applicationPathString == objectB.applicationPathString ) {
|
||
|
|
|
||
|
|
return objectB;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
return false;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
enableLog( path ) {
|
||
|
|
|
||
|
|
this.enabledPaths.push( path );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
register( object ) {
|
||
|
|
|
||
|
|
//this.enabled = true;
|
||
|
|
/*
|
||
|
|
var paths = this.enabledPaths;
|
||
|
|
|
||
|
|
for(var c = 0; c<paths.length;c++) {
|
||
|
|
|
||
|
|
var path = paths[c];
|
||
|
|
|
||
|
|
if( path == object.applicationPathString ) {
|
||
|
|
|
||
|
|
this.enabled = true;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if( !this.getObjectByPath( object ) ) {
|
||
|
|
|
||
|
|
this.objects.push( object );
|
||
|
|
|
||
|
|
console.log("add");
|
||
|
|
|
||
|
|
this.sendObjectToDebugger( object );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
this.currentObject = object;
|
||
|
|
*/
|
||
|
|
|
||
|
|
//this.log("clear_console");
|
||
|
|
this.log("--------------------------", object.getClassName() );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
sendObjectToDebugger( object ) {
|
||
|
|
|
||
|
|
var parameters = {};
|
||
|
|
|
||
|
|
parameters.action = "addObject";
|
||
|
|
|
||
|
|
parameters.object = cycle.decycle( object );
|
||
|
|
|
||
|
|
var socketManager = global.socketManager;
|
||
|
|
|
||
|
|
var clients = socketManager.clients;
|
||
|
|
|
||
|
|
for( var c = 0; c < clients.length; c++ ) {
|
||
|
|
|
||
|
|
var client = clients[c];
|
||
|
|
|
||
|
|
if( this.enabled ) {
|
||
|
|
|
||
|
|
client.debugMessage( parameters );
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
table( parameter1 ) {
|
||
|
|
|
||
|
|
if( global.clusterID == 1 ) {
|
||
|
|
|
||
|
|
console.table( parameter1 );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
warning( parameter1, parameter2, parameter3 ) {
|
||
|
|
|
||
|
|
if( global.clusterID == 1 ) {
|
||
|
|
|
||
|
|
if( parameter3 ) {
|
||
|
|
|
||
|
|
console.log( parameter1, parameter2, parameter3 );
|
||
|
|
|
||
|
|
} else if( parameter2 ) {
|
||
|
|
|
||
|
|
console.log( parameter1, parameter2 );
|
||
|
|
|
||
|
|
} else if( parameter1 ) {
|
||
|
|
|
||
|
|
console.log( tools.consoleColors().green( parameter1 ) );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
valid( parameter1, parameter2, parameter3 ) {
|
||
|
|
|
||
|
|
if( global.clusterID == 1 ) {
|
||
|
|
|
||
|
|
if( parameter3 ) {
|
||
|
|
|
||
|
|
console.log( parameter1, parameter2, parameter3 );
|
||
|
|
|
||
|
|
} else if( parameter2 ) {
|
||
|
|
|
||
|
|
console.log( tools.consoleColors().cyan( parameter1), tools.consoleColors().cyan(parameter2) );
|
||
|
|
|
||
|
|
} else if( parameter1 ) {
|
||
|
|
|
||
|
|
console.log( tools.consoleColors().green( parameter1 ) );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
log( parameter1, parameter2, parameter3 ) {
|
||
|
|
|
||
|
|
if( parameter3 ) {
|
||
|
|
|
||
|
|
console.log( parameter1, parameter2, parameter3 );
|
||
|
|
|
||
|
|
} else if( parameter2 ) {
|
||
|
|
|
||
|
|
console.log( parameter1, parameter2 );
|
||
|
|
|
||
|
|
} else if( parameter1 ) {
|
||
|
|
|
||
|
|
var parameter1 = deepclone( parameter1 );
|
||
|
|
|
||
|
|
tools.cleanObject(parameter1);
|
||
|
|
|
||
|
|
console.log( parameter1 );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
setWidth( width ) {
|
||
|
|
|
||
|
|
this.maxChars = width;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
addColumn( a, b, c, d ) {
|
||
|
|
|
||
|
|
var row = new Array();
|
||
|
|
|
||
|
|
if( a ) {
|
||
|
|
|
||
|
|
row.push( a );
|
||
|
|
|
||
|
|
this.maxChars[0] = Math.max( this.maxChars[0], a.length );
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
if( b ) {
|
||
|
|
|
||
|
|
row.push( b );
|
||
|
|
|
||
|
|
this.maxChars[1] = Math.max( this.maxChars[1], b.length );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if( c ) {
|
||
|
|
|
||
|
|
row.push( c );
|
||
|
|
|
||
|
|
this.maxChars[2] = Math.max( this.maxChars[2], c.length );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if( d ) {
|
||
|
|
|
||
|
|
row.push( d );
|
||
|
|
|
||
|
|
this.maxChars[3] = Math.max( this.maxChars[3], d.length );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
this.rows.push( row );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
logTable() {
|
||
|
|
|
||
|
|
//if( global.clusterID == 1 ) {
|
||
|
|
|
||
|
|
for (var i = 0; i < this.rows.length; i++) {
|
||
|
|
|
||
|
|
var row = this.rows[i];
|
||
|
|
|
||
|
|
if( row[0] ) {
|
||
|
|
|
||
|
|
console.log( " ", row[0].padEnd( this.maxChars[0] + this.padding ), row[1] );
|
||
|
|
|
||
|
|
} else if( row[0] ) {
|
||
|
|
|
||
|
|
//console.log( row[0] );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log("\n");
|
||
|
|
|
||
|
|
this.rows = new Array();
|
||
|
|
|
||
|
|
//}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
export default new Console();
|
||
|
|
|
||
|
|
|