tidy(ui): consolidate getLoggingContext builders

This commit is contained in:
psychedelicious 2024-08-02 13:26:28 +10:00
parent 8e1a70b008
commit ad9312e989
8 changed files with 31 additions and 24 deletions

View File

@ -30,7 +30,7 @@ export class CanvasBrushLine {
this.parent = parent; this.parent = parent;
this.manager = parent.manager; this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating brush line'); this.log.trace({ state }, 'Creating brush line');

View File

@ -29,7 +29,7 @@ export class CanvasEraserLine {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
this.manager = parent.manager; this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating eraser line'); this.log.trace({ state }, 'Creating eraser line');

View File

@ -39,7 +39,7 @@ export class CanvasImage {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
this.manager = parent.manager; this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating image'); this.log.trace({ state }, 'Creating image');

View File

@ -60,7 +60,7 @@ export class CanvasLayer {
constructor(state: LayerEntity, manager: CanvasManager) { constructor(state: LayerEntity, manager: CanvasManager) {
this.id = state.id; this.id = state.id;
this.manager = manager; this.manager = manager;
this.getLoggingContext = this.manager.buildEntityGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.debug({ state }, 'Creating layer'); this.log.debug({ state }, 'Creating layer');

View File

@ -591,19 +591,17 @@ export class CanvasManager {
}); });
} }
buildObjectGetLoggingContext = ( buildGetLoggingContext = (
instance: CanvasBrushLine | CanvasEraserLine | CanvasRect | CanvasImage | CanvasTransformer instance:
| CanvasBrushLine
| CanvasEraserLine
| CanvasRect
| CanvasImage
| CanvasTransformer
| CanvasLayer
| CanvasStagingArea
): GetLoggingContext => { ): GetLoggingContext => {
return (extra?: JSONObject): JSONObject => { if (instance instanceof CanvasLayer || instance instanceof CanvasStagingArea) {
return {
...instance.parent.getLoggingContext(),
objectId: instance.id,
...extra,
};
};
};
buildEntityGetLoggingContext = (instance: CanvasLayer | CanvasStagingArea): GetLoggingContext => {
return (extra?: JSONObject): JSONObject => { return (extra?: JSONObject): JSONObject => {
return { return {
...instance.manager.getLoggingContext(), ...instance.manager.getLoggingContext(),
@ -611,6 +609,15 @@ export class CanvasManager {
...extra, ...extra,
}; };
}; };
} else {
return (extra?: JSONObject): JSONObject => {
return {
...instance.parent.getLoggingContext(),
objectId: instance.id,
...extra,
};
};
}
}; };
logDebugInfo() { logDebugInfo() {

View File

@ -28,7 +28,7 @@ export class CanvasRect {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
this.manager = parent.manager; this.manager = parent.manager;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.trace({ state }, 'Creating rect'); this.log.trace({ state }, 'Creating rect');

View File

@ -22,7 +22,7 @@ export class CanvasStagingArea {
constructor(manager: CanvasManager) { constructor(manager: CanvasManager) {
this.id = getPrefixedId(CanvasStagingArea.TYPE); this.id = getPrefixedId(CanvasStagingArea.TYPE);
this.manager = manager; this.manager = manager;
this.getLoggingContext = this.manager.buildEntityGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.log.debug('Creating staging area'); this.log.debug('Creating staging area');

View File

@ -63,7 +63,7 @@ export class CanvasTransformer {
this.manager = parent.manager; this.manager = parent.manager;
this.transformTarget = transformTarget; this.transformTarget = transformTarget;
this.getLoggingContext = this.manager.buildObjectGetLoggingContext(this); this.getLoggingContext = this.manager.buildGetLoggingContext(this);
this.log = this.manager.buildLogger(this.getLoggingContext); this.log = this.manager.buildLogger(this.getLoggingContext);
this.subscriptions = []; this.subscriptions = [];