1
0
Fork 0
mirror of https://github.com/zplug/zplug synced 2024-05-22 23:46:13 +02:00

Minor modifications to existing logging implementation

This commit is contained in:
b4b4r07 2016-12-14 19:57:57 +09:00
parent 5b306cf8aa
commit 9cda2bdf07
6 changed files with 57 additions and 86 deletions

View File

@ -43,12 +43,7 @@ fi
for repo in "${repos[@]}"
do
# Evaluate IF tag and bypass existance check if conditions are not met
tags[if]="$(
__zplug::core::core::run_interfaces \
'if' \
"$repo" \
2> >(__zplug::io::log::capture)
)"
tags[if]="$(__zplug::core::core::run_interfaces 'if' "$repo")"
if [[ -n $tags[if] ]]; then
if ! eval "$tags[if]" 2> >(__zplug::io::log::capture) >/dev/null; then
$is_verbose && __zplug::io::print::die "$repo: (bypassed check)\n"
@ -56,12 +51,7 @@ do
fi
fi
tags[from]="$(
__zplug::core::core::run_interfaces \
'from' \
"$repo" \
2> >(__zplug::io::log::capture)
)"
tags[from]="$(__zplug::core::core::run_interfaces 'from' "$repo")"
if [[ -z "$tags[from]" ]]; then
not_installed_repos+=( "$repo" )
continue

View File

@ -7,8 +7,6 @@ fpath=(
"$fpath[@]"
)
zmodload zsh/system #for flock
zmodload zsh/parameter #for jobstates
autoload -Uz regexp-replace
autoload -Uz add-zsh-hook
autoload -Uz colors
@ -18,3 +16,5 @@ autoload -Uz zplug
colors
zmodload zsh/system
zmodload zsh/datetime
zmodload zsh/parameter

View File

@ -28,7 +28,7 @@ __zplug::core::cache::update()
__zplug::core::cache::commit()
{
local pkg hook pair
local pkg pair hook
local -A hook_load
local -A reply_hash
local -A load_commands
@ -49,13 +49,16 @@ __zplug::core::cache::commit()
defer_3_plugins=( ${(@f)reply_hash[defer_3_plugins]} )
unclassified_plugins=( ${(@f)reply_hash[unclassified_plugins]} )
for pair (${(@f)reply_hash[load_commands]}) load_commands+=( ${(@s:\0:)pair} )
for pair (${(@f)reply_hash[hook_load]}) hook_load+=( ${(@s:\0:)pair} )
for pair in ${reply_hash[hook_load]}
do
hook="${${(@s:\0:)pair}[2,-1]}"
done
repo="$reply_hash[repo]"
# Common parameter
param="--repo ${(qqq)repo}"
if [[ -n $hook_load[$repo] ]]; then
param+=" --hook ${(qqq)hook_load[$repo]}"
if [[ -n $hook ]]; then
param+=" --hook ${(qqq)hook}"
fi
# Record packages to cache file

View File

@ -53,23 +53,25 @@ __zplug::core::load::as_plugin()
local -i status_code=0
zstyle -s ':zplug:core:load' 'verbose' is_verbose
__zplug::utils::shell::getopts "$argv[@]" \
| while read key value; \
while (( $#argv > 0 ))
do
case "$key" in
_)
load_path="$value"
case "$argv[1]" in
--repo)
repo="$argv[2]"
shift
;;
repo)
repo="$value"
--hook)
hook="$argv[2]"
shift
;;
hook)
hook="$value"
;;
lazy)
--lazy)
is_lazy=true
;;
*)
load_path="$argv[1]"
;;
esac
shift
done
if $is_lazy; then
@ -91,7 +93,7 @@ __zplug::core::load::as_plugin()
fi
if (( $status_code == 0 )); then
if [[ -n $hook ]]; then
${=hook}
eval ${=hook}
fi
else
__zplug::job::handle::flock "$_zplug_cache[failed_repos]" "$repo"
@ -107,23 +109,26 @@ __zplug::core::load::as_command()
local -i status_code=0
zstyle -s ':zplug:core:load' 'verbose' is_verbose
__zplug::utils::shell::getopts "$argv[@]" \
| while read key value; \
while (( $#argv > 0 ))
do
case "$key" in
_)
load_path="$value"
case "$argv[1]" in
--repo)
repo="$argv[2]"
shift
;;
repo)
repo="$value"
--hook)
hook="$argv[2]"
shift
;;
path)
_path="$value"
--path)
_path="$argv[2]"
shift
;;
hook)
hook="$value"
*)
load_path="$argv[1]"
;;
esac
shift
done
{
@ -141,7 +146,7 @@ __zplug::core::load::as_command()
fi
if (( $status_code == 0 )); then
if [[ -n $hook ]]; then
${=hook}
eval ${=hook}
fi
else
__zplug::job::handle::flock "$_zplug_cache[failed_repos]" "$repo"

View File

@ -7,17 +7,12 @@ __zplug::io::log::with_json()
# - $functrace[@]
local -i i
local date level="${1:-"ERROR"}"
local level="${1:-"ERROR"}"
local message="$(<&0)"
# Assume the stdin that should be discarded to /dev/null
#message=( ${(@f)"$(<&0)"} )
#if (( $#message == 0 )); then
# return 1
#fi
local message="$(<&0)"
# https://tools.ietf.org/html/rfc3339#section-5.6
date="$(date +%FT%T%z | sed -E 's/(.*)([0-9][0-9])([0-9][0-9])/\1\2:\3/')"
if [[ -z $message ]]; then
return 0
fi
# Spit out to JSON
printf '{'
@ -25,25 +20,17 @@ __zplug::io::log::with_json()
printf '"shlvl": %d,' "$SHLVL"
printf '"level": "%s",' "$level"
printf '"dir": "%s",' "$PWD"
if (( $+commands[python] )); then
printf '"message": '
printf "$message" | __zplug::utils::shell::json_escape
printf ','
fi
printf '"trace": {'
printf '"message": '
printf "$message" | __zplug::utils::shell::json_escape
printf ','
printf '"trace": ['
for ((i = 1; i < $#functrace; i++))
do
# With comma
printf '"%s": "%s",' \
"$functrace[$i]" \
"$funcstack[$i]"
printf '"%s",' "$functrace[$i]"
done
# Without comma
printf '"%s": "%s"' \
"$functrace[$#functrace]" \
"$funcstack[$#funcstack]"
printf "},"
printf '"date": "%s"' "$date"
printf '"%s"' "$functrace[$#functrace]"
printf "],"
printf '"date": "%s"' "$(strftime "%FT%T%z" $EPOCHSECONDS)"
printf "}\n"
}

View File

@ -212,23 +212,9 @@ __zplug::utils::shell::eval()
__zplug::utils::shell::json_escape()
{
python -c 'import json,sys; print json.dumps(sys.stdin.read())'
return $status
#| perl -pe 's/\//\\\//g' \
if [[ -z $1 ]]; then
cat <&0
if (( $+commands[python] )); then
python -c 'import json,sys; print json.dumps(sys.stdin.read())'
else
if [[ -f $1 ]]; then
cat "$1"
else
echo "$1"
fi
fi \
| perl -pe 's/\\/\\\\/g' \
| perl -pe 's/"/\\"/g' \
| perl -pe 's/\f/\\f/g' \
| perl -pe 's/\r/\\r/g' \
| perl -pe 's/\n/\\n/g' \
| perl -pe 's/\t/\\t/g'
echo "(Not available: python requires)"
fi
}