-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5541 from NomicFoundation/debug-logs
Basic debug logging
- Loading branch information
Showing
6 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import debugLib from "debug"; | ||
|
||
/** | ||
* A simple decorator that adds debug logging for when a method is entered and exited. | ||
* | ||
* This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code. | ||
* | ||
* Example usage: | ||
* | ||
* ``` | ||
* class MyClass { | ||
* @withDebugLogs("MyClass:exampleClassMethod") | ||
* public function exampleClassMethod(...) | ||
* } | ||
* ``` | ||
*/ | ||
export function withDebugLogs<This, Args extends any[], Return>( | ||
tag: string = "", | ||
) { | ||
return function actualDecorator( | ||
originalMethod: (this: This, ...args: Args) => Return, | ||
_context: ClassMethodDecoratorContext< | ||
This, | ||
(this: This, ...args: Args) => Return | ||
>, | ||
): (this: This, ...args: Args) => Return { | ||
const log = debugLib(`hardhat:dev:core${tag === "" ? "" : `:${tag}`}`); | ||
|
||
function replacementMethod(this: This, ...args: Args): Return { | ||
log(`Entering method with args:`, args); | ||
const result = originalMethod.call(this, ...args); | ||
log(`Exiting method.`); | ||
return result; | ||
} | ||
|
||
return replacementMethod; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters