-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - fix(logger-plugin): log async completion in separate group #1269
base: master
Are you sure you want to change the base?
Changes from 4 commits
b7e8ebd
26b5460
68862ae
9a3aff6
d3cfa02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,14 @@ import { formatTime } from './internals'; | |
import { LogWriter } from './log-writer'; | ||
|
||
export class ActionLogger { | ||
private synchronousWorkEnded = false; | ||
private actionCompleted = false; | ||
private startedTime = new Date(); | ||
|
||
constructor(private action: any, private store: Store, private logWriter: LogWriter) {} | ||
|
||
dispatched(state: any) { | ||
const actionName = getActionTypeFromInstance(this.action); | ||
const formattedTime = formatTime(new Date()); | ||
|
||
const message = `action ${actionName} @ ${formattedTime}`; | ||
const message = this.getActionLogHeader(); | ||
this.logWriter.startGroup(message); | ||
|
||
// print payload only if at least one property is supplied | ||
|
@@ -22,14 +23,40 @@ export class ActionLogger { | |
} | ||
|
||
completed(nextState: any) { | ||
if (this.synchronousWorkEnded) { | ||
const message = `(async work completed) ${this.getActionLogHeader()}`; | ||
this.logWriter.startGroup(message); | ||
} | ||
this.logWriter.logGreen('next state', nextState); | ||
this.logWriter.endGroup(); | ||
this.actionCompleted = true; | ||
} | ||
|
||
errored(error: any) { | ||
if (this.synchronousWorkEnded) { | ||
const message = `(async work error) ${this.getActionLogHeader()}`; | ||
this.logWriter.startGroup(message); | ||
} | ||
this.logWriter.logRedish('next state after error', this.store.snapshot()); | ||
this.logWriter.logRedish('error', error); | ||
this.logWriter.endGroup(); | ||
this.actionCompleted = true; | ||
} | ||
|
||
syncWorkComplete() { | ||
if (!this.actionCompleted) { | ||
this.logWriter.logGreen('next state (synchronous)', this.store.snapshot()); | ||
this.logWriter.logGreen('( action doing async work... )', undefined); | ||
this.logWriter.endGroup(); | ||
} | ||
this.synchronousWorkEnded = true; | ||
} | ||
|
||
private getActionLogHeader() { | ||
const actionName = getActionTypeFromInstance(this.action); | ||
const formattedTime = formatTime(this.startedTime); | ||
const message = `action ${actionName} (started @ ${formattedTime})`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is redunant, you can return `action ${actionName} (started @ ${formattedTime})`; In addition, I recommend always describing the return type, since in the future you can forget to return an object instead of a returned string. private getActionLogHeader(): string {
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Will do |
||
return message; | ||
} | ||
|
||
private _hasPayload(event: any) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export type CallStack = (string | {})[][]; | ||
export type CallParam = string | {}; | ||
export type Call = CallParam[]; | ||
export type CallStack = Call[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
synchronousWorkEnded
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActionLogger
instance is created when any action is dispatched. As actions can be sync and async this is a flag that basically says "oh I've completed doing my synchronous job".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for some reason this is all very complicated, but oh well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more comments I guess