Skip to content

Commit

Permalink
feat: Improve logging mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailhabib committed May 25, 2018
1 parent d5441c7 commit 1744473
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/Actor.ts
Original file line number Diff line number Diff line change
@@ -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<T> = {
type: ValidActorMethodPropNames<T>;
Expand Down Expand Up @@ -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<any>).cancel();
}
Expand All @@ -142,6 +146,7 @@ export abstract class Actor {
type: string,
payload: any
): Promise<any> | CancellablePromise<any> {
this.log(`Handling message of type ${type} and payload ${payload}`);
return (this as any)[type](payload);
}

Expand Down
5 changes: 4 additions & 1 deletion src/ActorSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +171,6 @@ export class ActorSystem {
}

private log(...message: any[]) {
console.log(`ActorSystem (${this.name}): `, ...message);
myDebugger(`[${this.name}]`, ...message);
}
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
version "0.0.38"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.38.tgz#c1be40aa933723c608820a99a373a16d215a1ca2"
Expand Down

0 comments on commit 1744473

Please sign in to comment.