Skip to content

Commit

Permalink
fix: Add missing instances in logs, document instance field
Browse files Browse the repository at this point in the history
Change-Id: I797bca10b5b32c97f2bc106a0007dc1a380eb3c2
  • Loading branch information
joeyparrish committed Nov 8, 2021
1 parent 698770d commit 45cf349
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions trace-anything.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ class TraceAnything {

try {
const original = new ctor(...args);
const traced = TraceAnything.traceObject(original, options);

log.instance = traced;
log.result = original;
log.duration = Date.now() - log.timestamp;
options.logger(log);

return TraceAnything.traceObject(original, options);
return traced;
} catch (error) {
log.threw = error;
log.duration = Date.now() - log.timestamp;
Expand Down Expand Up @@ -331,8 +334,8 @@ class TraceAnything {
const log = {
timestamp: Date.now(),
type: TraceAnything.LogTypes.Method,
className,
instance: this,
className,
methodName: k,
args,
};
Expand Down Expand Up @@ -480,6 +483,7 @@ class TraceAnything {
timestamp: Date.now(),
duration: 0,
type: TraceAnything.LogTypes.Setter,
instance: traced,
className,
memberName: k,
value,
Expand All @@ -495,6 +499,7 @@ class TraceAnything {
const log = {
timestamp: Date.now(),
type: TraceAnything.LogTypes.Getter,
instance: traced,
className,
memberName: k,
};
Expand All @@ -520,6 +525,7 @@ class TraceAnything {
const log = {
timestamp: Date.now(),
type: TraceAnything.LogTypes.Setter,
instance: traced,
className,
memberName: k,
};
Expand Down Expand Up @@ -560,6 +566,7 @@ class TraceAnything {
timestamp: Date.now(),
duration: 0,
type: TraceAnything.LogTypes.Event,
instance: traced,
className,
eventName: `${k} Promise resolved`,
event: {
Expand All @@ -572,6 +579,7 @@ class TraceAnything {
timestamp: Date.now(),
duration: 0,
type: TraceAnything.LogTypes.Event,
instance: traced,
className,
eventName: `${k} Promise rejected`,
event: {
Expand Down Expand Up @@ -736,6 +744,7 @@ class TraceAnything {
timestamp: Date.now(),
duration: 0,
type: TraceAnything.LogTypes.Event,
instance: traced,
className,
eventName,
event,
Expand Down Expand Up @@ -829,6 +838,7 @@ TraceAnything.LogTypes = {
* timestamp: Number,
* duration: Number,
* type: TraceAnything.LogTypes,
* instance: (!Object|undefined),
* message: (string|undefined),
* className: (string|undefined),
* methodName: (string|undefined),
Expand All @@ -848,6 +858,8 @@ TraceAnything.LogTypes = {
* events or warnings.
* @property {TraceAnything.LogTypes} type
* The type of log.
* @property {(!Object|undefined)} instance
* The instance on which this method call / getter / setter / event occurred.
* @property {(string|undefined)} message
* A message for Warning-type logs.
* @property {(string|undefined)} className
Expand Down

0 comments on commit 45cf349

Please sign in to comment.