go intall github.com/robertranjan/gotrace@latest
gotrace annotates function calls in go source files with log statements on entry and exit.
❯ bin/gotrace help
NAME:
gotrace - trace go src func calls
USAGE:
gotrace [global options] command [command options] [arguments...]
VERSION:
v0.1.0
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--verbose run with verbosity (default: false) [$BUTLER_VERBOSE]
--debug run with debug logging (default: false) [$BUTLER_DEBUG]
--versionFlag versionFlag (default: false) [$BUTLER_VERSIONFLAG]
--exportedOnly exportedOnly (default: false) [$BUTLER_EXPORTEDONLY]
--showPackage showPackage (default: false) [$BUTLER_SHOWPACKAGE]
--writeFiles, -w writeFiles (default: false) [$BUTLER_WRITEFILES]
--timing timing (default: false) [$BUTLER_TIMING]
--showReturn showReturn (default: false) [$BUTLER_SHOWRETURN]
--prefix value prefix [$BUTLER_PREFIX]
--filterFlag value filterFlag [$BUTLER_FILTERFLAG]
--excludeFlag value excludeFlag [$BUTLER_EXCLUDEFLAG]
--formatLength value formatLength (default: 0) [$BUTLER_FORMATLENGTH]
--files value [ --files value ] go source files [$BUTLER_GOFILES]
--help, -h show help
--version, -v print the version
# gotrace operates directly on go source files.
# Insert gotrace logging statements into all *.go files in the current directory
# Make sure all files are saved in version control, as this rewrites them in-place!
$ gotrace -w -returns ./*.go
Go to a project with .go src files
-
Git commit all changes and make sure
git diff --exit-code exits
with 0 -
run below command to annotate
gotrace $(find . -type f -name *.go) --files file1,file2,...,fileN gotrace $(fd -e go)
you may need to add
-w
to write to the filesbin/gotrace --debug -w --files $(fd -e go| tr '\n' ',')
As all the files are already checked in and annotation can be done quickly on-demand,
you may simple git co .
to clean up the annotations.