Skip to content

Commit

Permalink
feat(log): Add log all support.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 27, 2017
1 parent 7a2cf50 commit c23e04c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ This method returns a teardown function.

```ts
function show(
partialLogger?: PartialLogger = console
partialLogger: PartialLogger = console
): void
function show(
match: string | RegExp | MatchPredicate | Observable<any>,
partialLogger?: PartialLogger = console
partialLogger: PartialLogger = console
): void
```

Expand All @@ -133,13 +133,17 @@ The logged information is retrieved from the most recent snapshot, so if snapsho
### log

```ts
function log(
partialLogger: PartialLogger = console
): () => void
function log(
match: string | RegExp | MatchPredicate | Observable<any>,
partialLogger: PartialLogger = console
): () => void
```

Wires up an instance of the log plugin for matching observables.
Wires up an instance of the log plugin for matching observables. If no `match` is specified, all tagged observables will be logged.

All `subscribe`, `next`, `complete`, `error` and `unsubscribe` events will be logged to the console or to the specified logger.

Expand Down
17 changes: 17 additions & 0 deletions source/spy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ describe("spy", () => {
expect(calls).to.not.be.empty;
expect(calls[0]).to.deep.equal(["Tag = people; event = unsubscribe"]);
});

it("should log all/any tagged observables", () => {

teardown = spy({ plugins: [] });

const subject = new Subject<string>();
const calls: any[][] = [];

log({
log(...args: any[]): void { calls.push(args); }
});

const subscription = subject.tag("people").subscribe();
expect(calls).to.not.be.empty;
expect(calls[0]).to.deep.equal(["Tag = people; event = subscribe"]);
expect(calls[1]).to.deep.equal([" Matching", "/.+/"]);
});
});

describe("patch", () => {
Expand Down
12 changes: 11 additions & 1 deletion source/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ export function flush(): void {
plugins_.forEach((plugin) => plugin.flush());
}

export function log(match: Match, partialLogger?: PartialLogger): () => void {
export function log(partialLogger?: PartialLogger): () => void;
export function log(match: Match, partialLogger?: PartialLogger): () => void;
export function log(match: any, partialLogger?: PartialLogger): () => void {

const anyTagged = /.+/;
if (!match) {
match = anyTagged;
} else if (typeof match.log === "function") {
partialLogger = match;
match = anyTagged;
}

return plugin(new LogPlugin(match, partialLogger), `log(${matchToString(match)})`);
}
Expand Down

0 comments on commit c23e04c

Please sign in to comment.