diff --git a/package.json b/package.json index 4ed204b..f03883b 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "mapCoverage": true }, "devDependencies": { + "@types/debug": "^0.0.30", "@types/express": "^4.11.1", "@types/jest": "^22.0.0", "@types/node": "^9.3.0", @@ -84,6 +85,7 @@ "coveralls": "^3.0.0", "cross-env": "^5.0.1", "cz-conventional-changelog": "^2.0.0", + "debug": "^3.1.0", "express": "^4.16.3", "husky": "^0.14.0", "jest": "^22.0.2", diff --git a/src/Actor.ts b/src/Actor.ts index 4ca6c7c..1bfd4b4 100644 --- a/src/Actor.ts +++ b/src/Actor.ts @@ -1,6 +1,9 @@ import { ActorSystem } from "./ActorSystem"; import { Address, Handler } from "./interfaces"; import { CancellablePromise } from "./Utils"; +import debug from "debug"; + +const myDebugger = debug("actor:actor"); export type MailBoxMessage = { type: ValidActorMethodPropNames; @@ -127,10 +130,11 @@ export abstract class Actor { }; protected log(...message: any[]) { - console.log(`${this.name}:`, ...message); + myDebugger(`[${this.name}]`, ...message); } protected cancelCurrentExecution = () => { + this.log("Cancel current execution"); if (this.currentPromise && typeof (this.currentPromise as any).cancel === "function") { (this.currentPromise as CancellablePromise).cancel(); } @@ -142,6 +146,7 @@ export abstract class Actor { type: string, payload: any ): Promise | CancellablePromise { + this.log(`Handling message of type ${type} and payload ${payload}`); return (this as any)[type](payload); } diff --git a/src/ActorSystem.ts b/src/ActorSystem.ts index ecdf07d..880674c 100644 --- a/src/ActorSystem.ts +++ b/src/ActorSystem.ts @@ -9,6 +9,9 @@ import { LocalAddress } from "./interfaces"; import * as uuid from "uuid"; +import debug from "debug"; + +const myDebugger = debug("actor:actor-system"); export class ActorSystem { name: string; @@ -168,6 +171,6 @@ export class ActorSystem { } private log(...message: any[]) { - console.log(`ActorSystem (${this.name}): `, ...message); + myDebugger(`[${this.name}]`, ...message); } } diff --git a/yarn.lock b/yarn.lock index fc3c9f1..3c63c13 100644 --- a/yarn.lock +++ b/yarn.lock @@ -119,6 +119,10 @@ dependencies: "@types/node" "*" +"@types/debug@^0.0.30": + version "0.0.30" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df" + "@types/estree@*", "@types/estree@0.0.38": version "0.0.38" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.38.tgz#c1be40aa933723c608820a99a373a16d215a1ca2"