Skip to content

Commit

Permalink
perf(template): add 2 new settings: $ASDF_LOG_QUIET and $ASDF_LOG_SILENT
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Sep 15, 2023
1 parent f85a73f commit 91dbefa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions templates/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ how to install & manage versions.
Plugins generated from asdf-plugin-template repository will
contains several extra features for every user including all below.

- `$DEBUG=<any-string>` to enabled debug mode
- `$DEBUG=<any-string>` to enabled debug mode (debug logs will guarantee to show regardless of other settings)
- `$ASDF_FORCE_DOWNLOAD=<any-string>` to always download even cache exist
- `$ASDF_INSECURE=<any-string>` to disable security features (e.g. checksum)
- `$ASDF_NO_CHECK=<any-string>` to disable pre-check features (e.g. check-cmd)
Expand All @@ -99,20 +99,23 @@ contains several extra features for every user including all below.
- **{namespace}** - for formatted namespace (always have same length)
- **{ns}** - for raw namespace (no formatting applied)
- **{message}** - for log message
- `$ASDF_LOG_QUIET=<any-string>` - to disable only info logs
- `$ASDF_LOG_SILENT=<any-string>` - to disable all logs (including warning and error)

### Addition Features

The plugins might contains additional features
in addition to default features above.
You can take a look at [README.plugin.md][app-readme]
You can take a look at [README.plugin.md][app-readme-md]

## Contributors

Read [CONTRIBUTING.md] file for more detail.
Read [CONTRIBUTING.md][contributing-md] file for more detail.

<!-- LINKS SECTION -->

[app-readme]: ./README.plugin.md
[app-readme-md]: ./README.plugin.md
[contributing-md]: ./CONTRIBUTING.md
[plugin-gh]: {{ url(plugin_org, plugin_name) }}
[template-gh]: https://github.com/kc-workspace/asdf-plugin-template
[asdf-link]: https://github.com/asdf-vm/asdf
Expand Down
12 changes: 12 additions & 0 deletions templates/lib/common/internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ __asdf_load() {
## usage: `kc_asdf_log '<level>' '<namespace>' '<format>' '<variables>'`
## variables:
## - ASDF_LOG_FORMAT="{datetime} [{level}] {namespace} - {message}"
## - ASDF_LOG_QUIET=true
## - ASDF_LOG_SILENT=true
__asdf_log() {
local level="$1" ns="$2" _format="$3"
shift 3

case "$level" in
## disable info logs if log_quiet or log_silent is set
"INF")
test -n "${ASDF_LOG_QUIET:-}" || test -n "${ASDF_LOG_SILENT:-}" &&
return 0
;;
"WRN") test -n "${ASDF_LOG_SILENT:-}" && return 0 ;;
"ERR") test -n "${ASDF_LOG_SILENT:-}" && return 0 ;;
esac

local default="{time} [{level}] {namespace} - {message}"
local template="${ASDF_LOG_FORMAT:-$default}"

Expand Down

0 comments on commit 91dbefa

Please sign in to comment.