Update logging

This commit is contained in:
Bill 2022-07-18 21:51:53 -04:00
parent c60f05b227
commit 8e828c1f7d
19 changed files with 897 additions and 918 deletions

View File

@ -130,7 +130,7 @@ export class AssetManager extends Disposable implements IAssetManager
{ {
if (!status) if (!status)
{ {
this._logger.error('Failed to download asset: ' + url); this._logger.error('Failed to download asset', url);
loader.destroy(); loader.destroy();

View File

@ -1,8 +1,8 @@
export interface INitroLogger export interface INitroLogger
{ {
log(message: string): void; log(...message: any[]): void;
error(message: string, trace?: string): void; error(...message: any[]): void;
warn(message: string): void; warn(...message: any[]): void;
description: string | number; description: string | number;
print: boolean; print: boolean;
} }

View File

@ -2,8 +2,6 @@ import { INitroLogger } from './INitroLogger';
export class NitroLogger implements INitroLogger export class NitroLogger implements INitroLogger
{ {
private static LAST_TIMESTAMP: number = Date.now();
private _name: string; private _name: string;
private _description: string | number; private _description: string | number;
private _print: boolean; private _print: boolean;
@ -15,66 +13,55 @@ export class NitroLogger implements INitroLogger
this._print = true; this._print = true;
} }
public log(message: string): void public log(...message: any[]): void
{ {
this.printMessage(message, 'log'); this.printMessage('log', ...message);
} }
public error(message: string, trace?: string): void public error(...message: any[]): void
{ {
this.printMessage(trace || message, 'error'); this.printMessage('error', ...message);
} }
public warn(message: string): void public warn(...message: any[]): void
{ {
this.printMessage(message, 'warn'); this.printMessage('warn', ...message);
} }
public printMessage(message: string, modus: string): void public printMessage(modus: string, ...message: any[]): void
{ {
if (!this._print) return; if (!this._print) return;
NitroLogger.log(message, this._name, modus); NitroLogger.log(this._name, modus, ...message);
} }
public static log(message: string, name: string = 'Nitro', modus: string = null): void public static log(name: string = 'Nitro', modus: string = null, ...message: any[]): void
{ {
const logString = `[Nitro] [${ name }] ${ message } ${ this.getTimestamp() }`; const logPrefix = `[Nitro] [${name}]`;
switch (modus) switch (modus)
{ {
case 'error': case 'error':
console.error(logString); console.error(logPrefix, ...message);
break; break;
case 'warn': case 'warn':
console.warn(logString); console.warn(logPrefix, ...message);
break; break;
case 'log': case 'log':
default: default:
console.log(logString); console.log(logPrefix, ...message);
break; break;
} }
} }
public static error(message: string, name: string = 'Nitro'): void public static error(name: string = 'Nitro', ...message: any[]): void
{ {
return this.log(message, name, 'error'); return this.log(name, 'error', ...message);
} }
public static warn(message: string, name: string = 'Nitro'): void public static warn(name: string = 'Nitro', ...message: any[]): void
{ {
return this.log(message, name, 'warn'); return this.log(name, 'warn', ...message);
}
public static getTimestamp(): string
{
const now = Date.now();
const result = ` +${ now - NitroLogger.LAST_TIMESTAMP || 0 }ms`;
this.LAST_TIMESTAMP = now;
return result;
} }
public get description(): string | number public get description(): string | number

View File

@ -1,5 +1,4 @@
import { Nitro } from '../../../nitro/Nitro'; import { Nitro } from '../../../nitro/Nitro';
import { NitroLogger } from '../../common/logger/NitroLogger';
import { EventDispatcher } from '../../events/EventDispatcher'; import { EventDispatcher } from '../../events/EventDispatcher';
import { EvaWireFormat } from '../codec/evawire/EvaWireFormat'; import { EvaWireFormat } from '../codec/evawire/EvaWireFormat';
import { ICodec } from '../codec/ICodec'; import { ICodec } from '../codec/ICodec';
@ -184,7 +183,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
if (header === -1) if (header === -1)
{ {
NitroLogger.log(`Unknown Composer: ${ composer.constructor.name }`); if (Nitro.instance.getConfiguration<boolean>('system.packet.log')) this.logger.log(`Unknown Composer: ${composer.constructor.name}`);
continue; continue;
} }
@ -194,12 +193,12 @@ export class SocketConnection extends EventDispatcher implements IConnection
if (!encoded) if (!encoded)
{ {
if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) console.log(`Encoding Failed: ${ composer.constructor.name }`); if (Nitro.instance.getConfiguration<boolean>('system.packet.log')) this.logger.log('Encoding Failed', composer.constructor.name);
continue; continue;
} }
if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) console.log(`OutgoingComposer: [${ header }] ${ composer.constructor.name }`, message); if (Nitro.instance.getConfiguration<boolean>('system.packet.log')) this.logger.log('OutgoingComposer', header, composer.constructor.name, message);
this.write(encoded.getBuffer()); this.write(encoded.getBuffer());
} }
@ -223,7 +222,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
catch (err) catch (err)
{ {
NitroLogger.log(err); this.logger.error(err);
} }
} }
@ -257,10 +256,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
if (!messages || !messages.length) continue; if (!messages || !messages.length) continue;
if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) if (Nitro.instance.getConfiguration<boolean>('system.packet.log')) this.logger.log('IncomingMessage', wrapper.header, messages[0].constructor.name, messages[0].parser);
{
console.log(`IncomingMessage: [${ wrapper.header }] ${ messages[0].constructor.name }`, messages[0].parser);
}
this.handleMessages(...messages); this.handleMessages(...messages);
} }
@ -291,10 +287,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
if (!events || !events.length) if (!events || !events.length)
{ {
if(Nitro.instance.getConfiguration<boolean>('system.packet.log')) if (Nitro.instance.getConfiguration<boolean>('system.packet.log')) this.logger.log('IncomingMessage', wrapper.header, 'UNREGISTERED', wrapper);
{
console.log(`IncomingMessage: [${ wrapper.header }] UNREGISTERED`, wrapper);
}
return; return;
} }
@ -311,7 +304,7 @@ export class SocketConnection extends EventDispatcher implements IConnection
catch (e) catch (e)
{ {
NitroLogger.log(`Error parsing message: ${ e }`, events[0].constructor.name); this.logger.error('Error parsing message', e, events[0].constructor.name);
return null; return null;
} }

View File

@ -66,7 +66,7 @@ export class EventDispatcher extends Disposable implements IEventDispatcher, IDi
{ {
if (!event) return false; if (!event) return false;
if(Nitro.instance.getConfiguration<boolean>('system.dispatcher.log')) this._logger.log(`DISPATCHED: ${ event.type }`); if (Nitro.instance.getConfiguration<boolean>('system.dispatcher.log')) this._logger.log('Dispatched Event', event.type);
this.processEvent(event); this.processEvent(event);
@ -110,4 +110,9 @@ export class EventDispatcher extends Disposable implements IEventDispatcher, IDi
{ {
this._listeners.clear(); this._listeners.clear();
} }
public get logger(): INitroLogger
{
return this._logger;
}
} }

View File

@ -1,3 +1,4 @@
import { INitroLogger } from '../common';
import { IDisposable } from '../common/disposable/IDisposable'; import { IDisposable } from '../common/disposable/IDisposable';
import { NitroEvent } from './NitroEvent'; import { NitroEvent } from './NitroEvent';
@ -7,4 +8,5 @@ export interface IEventDispatcher extends IDisposable
removeEventListener(type: string, callback: Function): void; removeEventListener(type: string, callback: Function): void;
removeAllListeners(): void; removeAllListeners(): void;
dispatchEvent(event: NitroEvent): boolean; dispatchEvent(event: NitroEvent): boolean;
logger: INitroLogger;
} }

View File

@ -1,5 +1,4 @@
import { IAssetManager } from '../../core/asset/IAssetManager'; import { IAssetManager } from '../../core/asset/IAssetManager';
import { NitroLogger } from '../../core/common/logger/NitroLogger';
import { EventDispatcher } from '../../core/events/EventDispatcher'; import { EventDispatcher } from '../../core/events/EventDispatcher';
import { NitroEvent } from '../../core/events/NitroEvent'; import { NitroEvent } from '../../core/events/NitroEvent';
import { Nitro } from '../Nitro'; import { Nitro } from '../Nitro';
@ -89,7 +88,7 @@ export class AvatarAssetDownloadManager extends EventDispatcher
catch (e) catch (e)
{ {
NitroLogger.log(e); this.logger.error(e);
} }
} }

View File

@ -1,4 +1,3 @@
import { NitroLogger } from '../../core';
import { IAssetManager } from '../../core/asset/IAssetManager'; import { IAssetManager } from '../../core/asset/IAssetManager';
import { NitroManager } from '../../core/common/NitroManager'; import { NitroManager } from '../../core/common/NitroManager';
import { NitroEvent } from '../../core/events/NitroEvent'; import { NitroEvent } from '../../core/events/NitroEvent';
@ -199,7 +198,7 @@ export class AvatarRenderManager extends NitroManager implements IAvatarRenderMa
if (!defaultFigureData || (typeof defaultFigureData === 'string')) if (!defaultFigureData || (typeof defaultFigureData === 'string'))
{ {
NitroLogger.log('XML figuredata is no longer supported.'); this.logger.error('XML figuredata is no longer supported');
return; return;
} }

View File

@ -1,5 +1,4 @@
import { IAssetManager } from '../../core/asset/IAssetManager'; import { IAssetManager } from '../../core/asset/IAssetManager';
import { NitroLogger } from '../../core/common/logger/NitroLogger';
import { EventDispatcher } from '../../core/events/EventDispatcher'; import { EventDispatcher } from '../../core/events/EventDispatcher';
import { NitroEvent } from '../../core/events/NitroEvent'; import { NitroEvent } from '../../core/events/NitroEvent';
import { Nitro } from '../Nitro'; import { Nitro } from '../Nitro';
@ -88,7 +87,7 @@ export class EffectAssetDownloadManager extends EventDispatcher
catch (e) catch (e)
{ {
NitroLogger.log(e); this.logger.error(e);
} }
} }

View File

@ -1,4 +1,3 @@
import { NitroLogger } from '../../../core/common/logger/NitroLogger';
import { EventDispatcher } from '../../../core/events/EventDispatcher'; import { EventDispatcher } from '../../../core/events/EventDispatcher';
import { NitroEvent } from '../../../core/events/NitroEvent'; import { NitroEvent } from '../../../core/events/NitroEvent';
import { IFigureSetData } from './IFigureSetData'; import { IFigureSetData } from './IFigureSetData';
@ -47,7 +46,7 @@ export class AvatarStructureDownload extends EventDispatcher
catch (e) catch (e)
{ {
NitroLogger.log(e); this.logger.error(e);
} }
} }
} }

View File

@ -1,4 +1,3 @@
import { NitroLogger } from '../../../core/common/logger/NitroLogger';
import { NitroManager } from '../../../core/common/NitroManager'; import { NitroManager } from '../../../core/common/NitroManager';
import { IConnection } from '../../../core/communication/connections/IConnection'; import { IConnection } from '../../../core/communication/connections/IConnection';
import { SocketConnectionEvent } from '../../../core/communication/events/SocketConnectionEvent'; import { SocketConnectionEvent } from '../../../core/communication/events/SocketConnectionEvent';
@ -118,7 +117,7 @@ export class NitroCommunicationDemo extends NitroManager
{ {
if (!this.getSSO()) if (!this.getSSO())
{ {
NitroLogger.log('Login without an SSO ticket is not supported'); this.logger.error('Login without an SSO ticket is not supported');
} }
this.dispatchCommunicationDemoEvent(NitroCommunicationDemoEvent.CONNECTION_HANDSHAKE_FAILED, connection); this.dispatchCommunicationDemoEvent(NitroCommunicationDemoEvent.CONNECTION_HANDSHAKE_FAILED, connection);

View File

@ -490,7 +490,7 @@ export class RoomContentLoader implements IFurnitureDataListener
{ {
image.onload = null; image.onload = null;
this._logger.error('Failed to download asset: ' + url); this._logger.error('Failed to download asset', url);
this._iconListener.onRoomContentLoaded(id, [type, param].join('_'), false); this._iconListener.onRoomContentLoaded(id, [type, param].join('_'), false);
}; };
@ -533,7 +533,7 @@ export class RoomContentLoader implements IFurnitureDataListener
{ {
if (!status) if (!status)
{ {
this._logger.error('Failed to download asset: ' + url); this._logger.error('Failed to download asset', url);
loader.destroy(); loader.destroy();

View File

@ -4,7 +4,6 @@ import { Matrix, Point, Rectangle } from '@pixi/math';
import { NitroSprite } from '../../core'; import { NitroSprite } from '../../core';
import { IDisposable } from '../../core/common/disposable/IDisposable'; import { IDisposable } from '../../core/common/disposable/IDisposable';
import { IUpdateReceiver } from '../../core/common/IUpdateReceiver'; import { IUpdateReceiver } from '../../core/common/IUpdateReceiver';
import { NitroLogger } from '../../core/common/logger/NitroLogger';
import { NitroManager } from '../../core/common/NitroManager'; import { NitroManager } from '../../core/common/NitroManager';
import { IConnection } from '../../core/communication/connections/IConnection'; import { IConnection } from '../../core/communication/connections/IConnection';
import { IMessageComposer } from '../../core/communication/messages/IMessageComposer'; import { IMessageComposer } from '../../core/communication/messages/IMessageComposer';
@ -372,14 +371,14 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
this._roomDatas.set(roomId, data); this._roomDatas.set(roomId, data);
NitroLogger.log('Room Engine not initilized yet, can not create room. Room data stored for later initialization.'); this.logger.warn('Room Engine not initilized yet, can not create room. Room data stored for later initialization.');
return; return;
} }
if (!roomMap) if (!roomMap)
{ {
NitroLogger.log('Room property messages received before floor height map, will initialize when floor height map received.'); this.logger.warn('Room property messages received before floor height map, will initialize when floor height map received.');
return; return;
} }

View File

@ -348,7 +348,7 @@ export class RoomObjectEventHandler extends Disposable implements IRoomCanvasMou
this.onRoomObjectDataRequestEvent((event as RoomObjectDataRequestEvent), roomId); this.onRoomObjectDataRequestEvent((event as RoomObjectDataRequestEvent), roomId);
return; return;
default: default:
NitroLogger.log(`Unhandled Event: ${event.constructor.name}`, `Object ID: ${event.object.id}`); NitroLogger.warn('Unhandled Event', event.constructor.name, 'Object ID', event.object.id);
return; return;
} }
} }

View File

@ -356,7 +356,7 @@ export class RoomObjectLogicFactory implements IRoomObjectLogicFactory
if (!logic) if (!logic)
{ {
NitroLogger.log(`Unknown Logic: ${ type }`); NitroLogger.warn('Unknown Logic', type);
return null; return null;
} }

View File

@ -187,7 +187,7 @@ export class RoomObjectVisualizationFactory implements IRoomObjectVisualizationF
if (!visualization) if (!visualization)
{ {
NitroLogger.log(`Unknown Visualization: ${ type }`); NitroLogger.log('Unknown Visualization', type);
return null; return null;
} }

View File

@ -29,8 +29,6 @@ export class FurnitureYoutubeLogic extends FurnitureLogic
{ {
if (!this.object || !this.eventDispatcher) return; if (!this.object || !this.eventDispatcher) return;
console.log(this.object);
this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.YOUTUBE, this.object)); this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.YOUTUBE, this.object));
} }
} }

View File

@ -32,7 +32,7 @@ export class FurnitureFireworksVisualization extends FurnitureAnimatedVisualizat
if (this._particleSystems) this._currentParticleSystem = this._particleSystems.getValue(scale); if (this._particleSystems) this._currentParticleSystem = this._particleSystems.getValue(scale);
else NitroLogger.log(('ERROR Particle systems could not be read! ' + this.object.type)); else NitroLogger.log('ERROR Particle systems could not be read!', this.object.type);
} }
else else
{ {