gabyx / Githooks

🦎 Githooks: per-repo and shared Git hooks with version control and auto update. [✩Star] if you're using it!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Verbose mode

mruz opened this issue · comments

Is it possible to set verbose mode to reduce the output generated by Githooks?
Can we only display a low level error message when debugging is enabled? I would love to see just the echo my script produces:

Branch name invalid format.
Required: [[:alpha:]]+-[[:digit:]]+[-[:alnum:]]+

instead of

🦎 Launching '[2]' local hooks [type: 'pre-commit', threads: '16'] ...
Branch name invalid format.
Required: [[:alpha:]]+-[[:digit:]]+[-[:alnum:]]+
⛑  Hook '/home/mariusz/repos/my-repo/.githooks/pre-commit/branch/format.yaml' failed!
   -> errors:
   ✗  Command failed: 'docker ["run" "--rm" "-v" "/home/mariusz/repos/my-repo:/mnt/workspace" "-w" "/mnt/workspace" "--user" "1000:100" "-e" "GITHOOKS_CONTAINER_RUN=true" "-e" "GITHOOKS_OS=linux" "-e" "GITHOOKS_ARCH=amd64" "-e" "STAGED_FILES=test.txt" "githooks-image:1.0.0" "/mnt/workspace/.githooks/pre-commit/branch/.format.sh"]'.
   ✗  exit status 1
⛔ Some hooks failed, check output for details:
   • 'ns:githooks-image/pre-commit/branch/format.yaml'
⛔ Fatal error -> Abort.

I am not sure if I understand your request correctly: You want a --quiet mode, correct? Such that the output does not look as above. The case for the above output was, that I always wanted to see what is actually crashing and how, IMO its better to be explicit to allow the user to run the command as well again and also see which Hook failed etc. Reducing the output to only the output from the hook will be confusing pretty quickly if things fail. But one could introduce a better log implementation to set the verbosity level basically I guess.

All output goes to stderr,because some hook's [stdout](https://github.com/gabyx/Githooks/blob/main/githooks/common/log.go#L174

) get read. Not in pre-commit.

One could set the log verbosity level possibly. Think it needs a PR I guess.
The log.go should maybe use a proper log library to set some verbosity levels, over env variable GITHOOKS_LOG_LEVEL (to be able to set it for the hooks). Currently info, warn, error are always on and debug uses a compile flag: https://github.com/gabyx/Githooks/blob/main/githooks/common/log.go#L238

Yes, I want to mute the low-level output for my colleagues, otherwise they may miss the high-level message. I can then ask to export GITHOOKS_LOG_LEVEL=debug to see what is actually crashing.