From d87d318af7fc9a40511588de8dd747d6cb43fd93 Mon Sep 17 00:00:00 2001 From: b4b4r07 Date: Wed, 14 Dec 2016 21:02:18 +0900 Subject: [PATCH] Redesigne the logging system and made it simple --- autoload/commands/__check__ | 2 +- autoload/commands/__clean__ | 4 +- autoload/options/__log__ | 18 ++--- base/core/add.zsh | 6 -- base/core/arguments.zsh | 12 ---- base/core/cache.zsh | 2 +- base/core/core.zsh | 9 +-- base/core/load.zsh | 2 +- base/core/migration.zsh | 6 -- base/core/self.zsh | 4 +- base/core/sources.zsh | 32 ++------- base/core/tags.zsh | 6 -- base/io/log.zsh | 133 ------------------------------------ base/io/print.zsh | 4 +- base/job/handle.zsh | 4 +- base/job/hook.zsh | 31 +-------- base/log/capture.zsh | 25 +++++++ base/log/format.zsh | 47 +++++++++++++ base/log/print.zsh | 9 +++ base/log/write.zsh | 5 ++ base/sources/gh-r.zsh | 12 ---- base/sources/gist.zsh | 6 -- base/sources/github.zsh | 26 +------ base/sources/local.zsh | 8 +-- base/sources/oh-my-zsh.zsh | 8 +-- base/sources/prezto.zsh | 8 +-- base/utils/awk.zsh | 4 +- base/utils/git.zsh | 36 ++-------- base/utils/omz.zsh | 8 +-- base/utils/shell.zsh | 12 +--- init.zsh | 1 + test/base/io/log.t | 12 ---- 32 files changed, 130 insertions(+), 372 deletions(-) delete mode 100644 base/io/log.zsh create mode 100644 base/log/capture.zsh create mode 100644 base/log/format.zsh create mode 100644 base/log/print.zsh create mode 100644 base/log/write.zsh delete mode 100644 test/base/io/log.t diff --git a/autoload/commands/__check__ b/autoload/commands/__check__ index f09b307..5e42cd2 100644 --- a/autoload/commands/__check__ +++ b/autoload/commands/__check__ @@ -45,7 +45,7 @@ do # Evaluate IF tag and bypass existance check if conditions are not met 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 + if ! eval "$tags[if]" 2> >(__zplug::log::capture::error) >/dev/null; then $is_verbose && __zplug::io::print::die "$repo: (bypassed check)\n" continue fi diff --git a/autoload/commands/__clean__ b/autoload/commands/__clean__ index 89d40e8..dbad272 100644 --- a/autoload/commands/__clean__ +++ b/autoload/commands/__clean__ @@ -75,7 +75,7 @@ else __zplug::core::core::run_interfaces \ 'dir' \ "$repo" \ - 2> >(__zplug::io::log::capture) + 2> >(__zplug::log::capture::error) )" if [[ -d $tags[dir] ]]; then case "$tags[from]" in @@ -110,7 +110,7 @@ do # Clear cache __zplug::core::core::run_interfaces 'clear' fi \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null __zplug::io::print::put "\n" done diff --git a/autoload/options/__log__ b/autoload/options/__log__ index 3b40836..2a48b6f 100644 --- a/autoload/options/__log__ +++ b/autoload/options/__log__ @@ -2,12 +2,12 @@ # Description: # Show the report of zplug errors -if [[ ! -f $ZPLUG_ERROR_LOG ]] || [[ ! -s $ZPLUG_ERROR_LOG ]]; then +if [[ ! -f $_zplug_log[trace] ]] || [[ ! -s $_zplug_log[trace] ]]; then __zplug::io::print::f \ --die \ --zplug \ --error \ - "ZPLUG_ERROR_LOG: is not found or empty\n" + "The trace log is not found or empty\n" return 1 fi @@ -18,21 +18,21 @@ do arg="$1" case "$arg" in edit) - ${=${2:+$2}:-${EDITOR:-vim}} "$ZPLUG_ERROR_LOG" + ${=${2:+$2}:-${EDITOR:-vim}} "$_zplug_log[trace]" return $status ;; jq) if (( ! $+commands[jq] )); then return 1 fi - cat "$ZPLUG_ERROR_LOG" \ + cat "$_zplug_log[trace]" \ | sed -e 's/[[:cntrl:]]//g' \ | jq ${=${2:+"$argv[2,-1]"}:-"."} return $status ;; less | more) # $PAGER - cat "$ZPLUG_ERROR_LOG" \ + cat "$_zplug_log[trace]" \ | $arg return $status ;; @@ -40,16 +40,16 @@ do # compatible ;; clear) - rm -f "$ZPLUG_ERROR_LOG" + rm -f "$_zplug_log[trace]" return $status ;; count) - cat "$ZPLUG_ERROR_LOG" \ + cat "$_zplug_log[trace]" \ | grep -c '' return $status ;; latest) - cat "$ZPLUG_ERROR_LOG" \ + cat "$_zplug_log[trace]" \ | tail -n ${${2:+"$argv[2,-1]"}:-1} \ | ${=${${commands[jq]:+"jq ."}:-"cat -"}} return $status @@ -66,4 +66,4 @@ do shift done -cat "$ZPLUG_ERROR_LOG" +cat "$_zplug_log[trace]" diff --git a/base/core/add.zsh b/base/core/add.zsh index 6c6ca01..76adc7f 100644 --- a/base/core/add.zsh +++ b/base/core/add.zsh @@ -73,12 +73,6 @@ __zplug::core::add::proc_at-sign() local name="$1" key local -i max=0 - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - for key in "${(k)zplugs[@]}" do if [[ $key =~ ^$name@*$ ]] && (( $max < $#key )); then diff --git a/base/core/arguments.zsh b/base/core/arguments.zsh index 3011b8a..222a94e 100644 --- a/base/core/arguments.zsh +++ b/base/core/arguments.zsh @@ -2,12 +2,6 @@ __zplug::core::arguments::exec() { local arg="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - reply=() __zplug::core::commands::user_defined @@ -31,12 +25,6 @@ __zplug::core::arguments::auto_correct() local -i ret=0 local -a cmds reply_cmds - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - reply_cmds=() # Add user-defined commands diff --git a/base/core/cache.zsh b/base/core/cache.zsh index e5cec14..7b867ce 100644 --- a/base/core/cache.zsh +++ b/base/core/cache.zsh @@ -110,7 +110,7 @@ __zplug::core::cache::diff() $ZPLUG_USE_CACHE || return 2 if [[ -d $ZPLUG_CACHE_DIR ]]; then - 2> >(__zplug::io::log::capture) >/dev/null \ + 2> >(__zplug::log::capture::error) >/dev/null \ diff -b \ <(__zplug::core::cache::expose) \ <(__zplug::core::interface::expose) diff --git a/base/core/core.zsh b/base/core/core.zsh index d633362..3b5a87a 100644 --- a/base/core/core.zsh +++ b/base/core/core.zsh @@ -69,12 +69,6 @@ __zplug::core::core::run_interfaces() local interface local -i ret=0 - if [[ -z $arg ]]; then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - interface="__${arg:gs:_:}__" # Do autoload if not exists in $functions @@ -219,8 +213,7 @@ __zplug::core::core::variable() typeset -gx -A _zplug_log _zplug_build_log _zplug_log=( - "error" "$ZPLUG_HOME/log/error.log" - "execution" "$ZPLUG_HOME/log/execution.log" + "trace" "$ZPLUG_HOME/log/trace.log" "install" "$ZPLUG_HOME/log/install.log" "update" "$ZPLUG_HOME/log/update.log" "status" "$ZPLUG_HOME/log/status.log" diff --git a/base/core/load.zsh b/base/core/load.zsh index b147f99..3ae3d54 100644 --- a/base/core/load.zsh +++ b/base/core/load.zsh @@ -193,7 +193,7 @@ __zplug::core::load::skip_condition() fi if [[ -n $tags[if] ]]; then - if ! eval "$tags[if]" 2> >(__zplug::io::log::capture) >/dev/null; then + if ! eval "$tags[if]" 2> >(__zplug::log::capture::error) >/dev/null; then if (( $_zplug_boolean_true[(I)$is_verbose] )); then __zplug::io::print::die "$tags[name]: (not loaded)\n" fi diff --git a/base/core/migration.zsh b/base/core/migration.zsh index 80377d5..a70d1a7 100644 --- a/base/core/migration.zsh +++ b/base/core/migration.zsh @@ -2,12 +2,6 @@ __zplug::core::migration::tags() { local key="$1" new_key - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - case "$key" in "of") new_key="use" diff --git a/base/core/self.zsh b/base/core/self.zsh index 2f76054..b0a5646 100644 --- a/base/core/self.zsh +++ b/base/core/self.zsh @@ -5,7 +5,7 @@ __zplug::core::self::init() local dst="$ZPLUG_HOME/init.zsh" if [[ ! -f $src ]]; then - __zplug::io::log::error \ + __zplug::log::write::error \ "$src: no such file or directory" return 1 fi @@ -53,7 +53,7 @@ __zplug::core::self::update() "$_ZPLUG_VERSION" \ "$em[under]$HEAD[1,8]$reset_color" - __zplug::io::log::info "zplug is up-to-date" + __zplug::log::write::info "zplug is up-to-date" return $_zplug_status[self_return] } diff --git a/base/core/sources.zsh b/base/core/sources.zsh index 9e8c428..75fcb22 100644 --- a/base/core/sources.zsh +++ b/base/core/sources.zsh @@ -2,12 +2,6 @@ __zplug::core::sources::is_exists() { local source_name="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - [[ -f $ZPLUG_ROOT/base/sources/$source_name.zsh ]] return $status } @@ -17,12 +11,6 @@ __zplug::core::sources::is_handler_defined() local subcommand="$1" source_name="$2" handler_name handler_name="__zplug::sources::$source_name::$subcommand" - if (( $# < 2 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - if ! __zplug::core::sources::is_exists "$source_name"; then return $_zplug_status[failure] fi @@ -40,17 +28,11 @@ __zplug::core::sources::use_handler() repo="$3" local handler_name="__zplug::sources::$source_name::$subcommand" - if (( $# < 3 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 + if ! __zplug::core::sources::is_handler_defined "$subcommand" "$source_name"; then + # Callback function is undefined + return $_zplug_status[failure] fi - if ! __zplug::core::sources::is_handler_defined "$subcommand" "$source_name"; then - # Callback function is undefined - return $_zplug_status[failure] - fi - eval "$handler_name '$repo'" return $status } @@ -59,12 +41,6 @@ __zplug::core::sources::call() { local val="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - if __zplug::core::sources::is_exists "$val"; then { # Directory '/base/sources' needs to be included in FPATH @@ -72,7 +48,7 @@ __zplug::core::sources::call() eval "$val.zsh" unfunction "$val.zsh" } \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null fi } diff --git a/base/core/tags.zsh b/base/core/tags.zsh index 917089e..5cdcd3b 100644 --- a/base/core/tags.zsh +++ b/base/core/tags.zsh @@ -11,12 +11,6 @@ __zplug::core::tags::parse() local -A tags local -a pairs - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::core::tags::get tags=( "${reply[@]}" ) diff --git a/base/io/log.zsh b/base/io/log.zsh deleted file mode 100644 index 8b6978a..0000000 --- a/base/io/log.zsh +++ /dev/null @@ -1,133 +0,0 @@ -__zplug::io::log::with_json() -{ - # Variables for error report - # - $funcfiletrace[@] - # - $funcsourcetrace[@] - # - $funcstack[@] - # - $functrace[@] - - local -i i - local level="${1:-"ERROR"}" - local message="$(<&0)" - - if [[ -z $message ]]; then - return 0 - fi - - # Spit out to JSON - printf '{' - printf '"pid": %d,' "$$" - printf '"shlvl": %d,' "$SHLVL" - printf '"level": "%s",' "$level" - printf '"dir": "%s",' "$PWD" - printf '"message": ' - printf "$message" | __zplug::utils::shell::json_escape - printf ',' - printf '"trace": [' - for ((i = 1; i < $#functrace; i++)) - do - printf '"%s",' "$functrace[$i]" - done - printf '"%s"' "$functrace[$#functrace]" - printf "]," - printf '"date": "%s"' "$(strftime "%FT%T%z" $EPOCHSECONDS)" - printf "}\n" -} - -__zplug::io::log::level() -{ - local level="${(U)1:-"INFO"}" log_level - local -i part="${2:-2}" - local -A syslog_code - - # https://tools.ietf.org/html/rfc5424 - syslog_code=( - '' '0:Emergency:system is unusable' - '' '1:Alert:action must be taken immediately' - '' '2:Critical:critical conditions' - 'ERROR' '3:Error:error conditions' - 'WARN' '4:Warning:warning conditions' - '' '5:Notice:normal but significant condition' - 'INFO' '6:Informational:informational messages' - 'DEBUG' '7:Debug:debug-level messages' - ) - - if (( ! $+syslog_code[$level] )); then - level="INFO" - fi - if (( $part > 3 )); then - part=0 - fi - - echo "$syslog_code[$level]" \ - | awk -F: '{print $'"$part"'}' \ - | read log_level - - echo "${(U)log_level}" -} - -__zplug::io::log::new() -{ - local key value - local level="WARN" - local -a args - - __zplug::utils::shell::getopts "$argv[@]" \ - | while read key value; \ - do - case "$key" in - level) - level="$value" - ;; - _) - args+=( "$value" ) - esac - done - level="$(__zplug::io::log::level "$level")" - - echo "$args[@]" \ - | __zplug::io::log::with_json "$level" \ - | >>|"$ZPLUG_ERROR_LOG" -} - -__zplug::io::log::capture() -{ - __zplug::io::log::with_json "ERROR" \ - | >>|"$ZPLUG_ERROR_LOG" -} - -__zplug::io::log::capture_error() -{ - __zplug::io::log::with_json "ERROR" \ - | >>|"$_zplug_log[error]" -} - -__zplug::io::log::capture_execution() -{ - __zplug::io::log::with_json "DEBUG" \ - | >>|"$_zplug_log[execution]" -} - -__zplug::io::log::info() -{ - __zplug::io::log::new \ - --level="INFO" \ - -- \ - "$argv[@]" -} - -__zplug::io::log::warn() -{ - __zplug::io::log::new \ - --level="WARN" \ - -- \ - "$argv[@]" -} - -__zplug::io::log::error() -{ - __zplug::io::log::new \ - --level="ERROR" \ - -- \ - "$argv[@]" -} diff --git a/base/io/print.zsh b/base/io/print.zsh index d77075f..02040c4 100644 --- a/base/io/print.zsh +++ b/base/io/print.zsh @@ -138,7 +138,7 @@ __zplug::io::print::f() } >&$fd if $is_log; then - __zplug::io::log::error \ - "${(q)texts[@]}" + __zplug::log::write::error \ + "$texts[@]" fi } diff --git a/base/job/handle.zsh b/base/job/handle.zsh index 9153ee8..4ed17aa 100644 --- a/base/job/handle.zsh +++ b/base/job/handle.zsh @@ -15,10 +15,10 @@ __zplug::job::handle::flock() printf " timeout." fi printf "\n" - } 1> >(__zplug::io::log::capture) + } 1> >(__zplug::log::capture::error) return 1 fi - break + return 1 fi done diff --git a/base/job/hook.zsh b/base/job/hook.zsh index 9150b0d..e478d0b 100644 --- a/base/job/hook.zsh +++ b/base/job/hook.zsh @@ -3,12 +3,6 @@ __zplug::job::hook::service() local repo="$1" hook="$2" local -A tags - if (( $# < 2 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::core::tags::parse "$repo" tags=( "${reply[@]}" ) @@ -30,18 +24,9 @@ __zplug::job::hook::service() # Save a result to the log file (stdout/stderr) eval "$tags[$hook]" \ - 2> >(__zplug::io::log::capture_error) \ - 1> >(__zplug::io::log::capture_execution) + 2> >(__zplug::log::capture::error) \ + 1> >(__zplug::log::capture::debug) return $status - - #if (( $status != 0 )); then - # __zplug::io::print::f \ - # --die \ - # --zplug \ - # --error \ - # "'%s' failed\n" \ - # "$tags[$hook]" - #fi ) fi } @@ -50,12 +35,6 @@ __zplug::job::hook::build() { local repo="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::job::hook::service \ "$repo" \ "hook-build" @@ -66,12 +45,6 @@ __zplug::job::hook::load() { local repo="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::job::hook::service \ "$repo" \ "hook-load" diff --git a/base/log/capture.zsh b/base/log/capture.zsh new file mode 100644 index 0000000..b7b8987 --- /dev/null +++ b/base/log/capture.zsh @@ -0,0 +1,25 @@ +__zplug::log::capture::error() +{ + local message="$(<&0)" + + if [[ -z $message ]]; then + return 0 + fi + + __zplug::log::format::with_json \ + --level "ERROR" --message "$message" "$argv[@]" \ + >>|"$_zplug_log[trace]" +} + +__zplug::log::capture::debug() +{ + local message="$(<&0)" + + if [[ -z $message ]]; then + return 0 + fi + + __zplug::log::format::with_json \ + --level "DEBUG" --message "$message" "$argv[@]" \ + >>|"$_zplug_log[trace]" +} diff --git a/base/log/format.zsh b/base/log/format.zsh new file mode 100644 index 0000000..728a3d6 --- /dev/null +++ b/base/log/format.zsh @@ -0,0 +1,47 @@ +__zplug::log::format::with_json() +{ + local -i i=1 + local level="${1:-"INFO"}" message + local is_message_json=false + + while (( $#argv > 0 )) + do + case "$argv[1]" in + --message) + message="$argv[2]"; shift + ;; + --level) + level="$argv[2]"; shift + ;; + --message-json) + is_message_json=true + ;; + esac + shift + done + + # Spit out to JSON + printf '{' + printf '"pid":%d,' "$$" + printf '"shlvl":%d,' "$SHLVL" + printf '"level":"%s",' "$level" + printf '"dir":"%s",' "$PWD" + printf '"message":' + if $is_message_json; then + printf "$message" + else + printf "$message" \ + | __zplug::utils::shell::json_escape \ + | tr -d '\n' + fi + printf ',' + printf '"trace":[' + for ((i = 1; i < $#functrace; i++)) + do + printf '"%s",' "$functrace[$i]" + done + printf '"%s"' "$functrace[$#functrace]" + printf "]," + printf '"date":"%s"' "$(strftime "%FT%T%z" $EPOCHSECONDS)" + printf "}\n" +} diff --git a/base/log/print.zsh b/base/log/print.zsh new file mode 100644 index 0000000..f1a2e68 --- /dev/null +++ b/base/log/print.zsh @@ -0,0 +1,9 @@ +__zplug::log::print::error() +{ + # No problem since this function ignores + # unrelated arguments passed + __zplug::log::format::with_json \ + --level "ERROR" \ + --message "$argv[1]" \ + "$argv[2,-1]" +} diff --git a/base/log/write.zsh b/base/log/write.zsh new file mode 100644 index 0000000..d8d1e0f --- /dev/null +++ b/base/log/write.zsh @@ -0,0 +1,5 @@ +__zplug::log::write::error() +{ + __zplug::log::print::error "$argv[@]" \ + >>|"$_zplug_log[trace]" +} diff --git a/base/sources/gh-r.zsh b/base/sources/gh-r.zsh index 1b64b9d..60e47a7 100644 --- a/base/sources/gh-r.zsh +++ b/base/sources/gh-r.zsh @@ -22,12 +22,6 @@ __zplug::sources::gh-r::install() { local repo="$1" url - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - url="$( __zplug::utils::releases::get_url \ "$repo" @@ -43,12 +37,6 @@ __zplug::sources::gh-r::update() local repo="$1" index url local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[dir]="$(__zplug::core::core::run_interfaces 'dir' "$repo")" tags[use]="$(__zplug::core::core::run_interfaces 'use' "$repo")" tags[at]="$(__zplug::core::core::run_interfaces 'at' "$repo")" diff --git a/base/sources/gist.zsh b/base/sources/gist.zsh index fc3bc32..4359cdf 100644 --- a/base/sources/gist.zsh +++ b/base/sources/gist.zsh @@ -17,12 +17,6 @@ __zplug::sources::gist::get_url() { local repo="$1" url_format - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - case "$ZPLUG_PROTOCOL" in HTTPS | https) # https://git::@github.com/%s.git diff --git a/base/sources/github.zsh b/base/sources/github.zsh index d0ccc8d..323b7e6 100644 --- a/base/sources/github.zsh +++ b/base/sources/github.zsh @@ -3,12 +3,6 @@ __zplug::sources::github::check() local repo="$1" local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[dir]="$( __zplug::core::core::run_interfaces \ 'dir' \ @@ -23,12 +17,6 @@ __zplug::sources::github::install() { local repo="$1" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::utils::git::clone "$repo" return $status } @@ -39,12 +27,6 @@ __zplug::sources::github::update() local rev_local rev_remote rev_base local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[dir]="$(__zplug::core::core::run_interfaces 'dir' "$repo")" tags[at]="$(__zplug::core::core::run_interfaces 'at' "$repo")" @@ -60,12 +42,6 @@ __zplug::sources::github::get_url() { local repo="$1" url_format - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - case "$ZPLUG_PROTOCOL" in HTTPS | https) # Create the format of URL used to git clone @@ -179,7 +155,7 @@ __zplug::sources::github::load_plugin() if [[ -n $tags[ignore] ]]; then ignore_patterns=( $( zsh -c "$_ZPLUG_CONFIG_SUBSHELL; echo ${tags[dir]}/${~tags[ignore]}" \ - 2> >(__zplug::io::log::capture) + 2> >(__zplug::log::capture::error) )(N) ) for ignore in "${ignore_patterns[@]}" do diff --git a/base/sources/local.zsh b/base/sources/local.zsh index a612876..68278c5 100644 --- a/base/sources/local.zsh +++ b/base/sources/local.zsh @@ -5,12 +5,6 @@ __zplug::sources::local::check() local expanded_path local -a expanded_paths - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - __zplug::core::tags::parse "$repo" tags=( "${reply[@]}" ) @@ -27,7 +21,7 @@ __zplug::sources::local::check() fi done - __zplug::io::log::warn \ + __zplug::log::write::error \ "no matching file or directory in $tags[dir]" return 1 } diff --git a/base/sources/oh-my-zsh.zsh b/base/sources/oh-my-zsh.zsh index 3d9a7fe..85e390a 100644 --- a/base/sources/oh-my-zsh.zsh +++ b/base/sources/oh-my-zsh.zsh @@ -32,12 +32,6 @@ __zplug::sources::oh-my-zsh::update() local repo="$1" local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[dir]="$( __zplug::core::core::run_interfaces \ 'dir' \ @@ -158,7 +152,7 @@ __zplug::sources::oh-my-zsh::load_plugin() if [[ -n $tags[ignore] ]]; then ignore_patterns=( $( zsh -c "$_ZPLUG_CONFIG_SUBSHELL; echo ${tags[dir]}/${~tags[ignore]}" \ - 2> >(__zplug::io::log::capture) + 2> >(__zplug::log::capture::error) )(N) ) for ignore in "${ignore_patterns[@]}" do diff --git a/base/sources/prezto.zsh b/base/sources/prezto.zsh index ca47f07..171ac1c 100644 --- a/base/sources/prezto.zsh +++ b/base/sources/prezto.zsh @@ -32,12 +32,6 @@ __zplug::sources::prezto::update() local repo="$1" local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[dir]="$( __zplug::core::core::run_interfaces \ 'dir' \ @@ -170,7 +164,7 @@ __zplug::sources::prezto::load_plugin() if [[ -n $tags[ignore] ]]; then ignore_patterns=( $( zsh -c "$_ZPLUG_CONFIG_SUBSHELL; echo ${tags[dir]}/${~tags[ignore]}" \ - 2> >(__zplug::io::log::capture) + 2> >(__zplug::log::capture::error) )(N) ) for ignore in "${ignore_patterns[@]}" do diff --git a/base/utils/awk.zsh b/base/utils/awk.zsh index 343cfbd..ef942bb 100644 --- a/base/utils/awk.zsh +++ b/base/utils/awk.zsh @@ -14,7 +14,7 @@ __zplug::utils::awk::path() # There is no awk execute file in this PATH if (( $#awk_paths == 0 )); then - __zplug::io::log::warn \ + __zplug::log::write::error \ "gawk or nawk is not found" return 1 fi @@ -42,7 +42,7 @@ __zplug::utils::awk::path() done if [[ $awk == "" || $variant == "mawk" ]]; then - __zplug::io::log::warn \ + __zplug::log::write::error \ "gawk or nawk is not found" return 1 fi diff --git a/base/utils/git.zsh b/base/utils/git.zsh index ee1abd9..441d4f6 100644 --- a/base/utils/git.zsh +++ b/base/utils/git.zsh @@ -5,12 +5,6 @@ __zplug::utils::git::clone() local -i ret=1 local -A tags default_tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - # A validation of ZPLUG_PROTOCOL # - HTTPS (recommended) # - SSH @@ -69,7 +63,7 @@ __zplug::utils::git::clone() --recursive \ ${=depth_option} \ "$url_format" "$tags[dir]" \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null ret=$status fi @@ -89,12 +83,6 @@ __zplug::utils::git::checkout() local -a do_not_checkout local -A tags - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - tags[at]="$(__zplug::core::core::run_interfaces 'at' "$repo")" tags[dir]="$(__zplug::core::core::run_interfaces 'dir' "$repo")" tags[from]="$(__zplug::core::core::run_interfaces 'from' "$repo")" @@ -126,7 +114,7 @@ __zplug::utils::git::checkout() fi git checkout -q "$tags[at]" \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null if (( $status != 0 )); then __zplug::io::print::f \ --die \ @@ -179,7 +167,7 @@ __zplug::utils::git::merge() git fetch fi git checkout -q "$git[branch]" - } 2> >(__zplug::io::log::capture) >/dev/null + } 2> >(__zplug::log::capture::error) >/dev/null git[local]="$(git rev-parse HEAD)" git[upstream]="$(git rev-parse "@{upstream}")" @@ -202,7 +190,7 @@ __zplug::utils::git::merge() failed=true fi } \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null elif [[ $git[upstream] == $git[base] ]]; then # need to push @@ -229,12 +217,6 @@ __zplug::utils::git::status() local key val line local -A tags revisions - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - git ls-remote --heads --tags https://github.com/"$repo".git \ | awk '{print $2,$1}' \ | sed -E 's@^refs/(heads|tags)/@@g' \ @@ -285,15 +267,9 @@ __zplug::utils::git::get_remote_name() { local branch="$1" remote_name - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - remote_name="$(git config branch.${branch}.remote)" if [[ -z $remote_name ]]; then - __zplug::io::log::warn \ + __zplug::log::write::error \ "no remote repository" return 1 fi @@ -331,7 +307,7 @@ __zplug::utils::git::get_remote_state() origin_head="${$(git ls-remote origin HEAD)[1]}" git rev-parse -q "$origin_head" \ - 2> >(__zplug::io::log::capture) >/dev/null + 2> >(__zplug::log::capture::error) >/dev/null if (( $status != 0 )); then state="local out of date" elif (( $ahead > 0 )); then diff --git a/base/utils/omz.zsh b/base/utils/omz.zsh index f6367a9..a58d35b 100644 --- a/base/utils/omz.zsh +++ b/base/utils/omz.zsh @@ -7,12 +7,6 @@ __zplug::utils::omz::depends() local -A omz_libs local omz_repo="$ZPLUG_REPOS/$_ZPLUG_OHMYZSH" - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - for lib_f in "$omz_repo"/lib/*.zsh(.) do # List funcname in the library file @@ -39,7 +33,7 @@ __zplug::utils::omz::depends() [[ -f $t ]] || continue sed '/^ *#/d' "$t" \ | egrep "(^|\s|['\"(\`])$lib_f($|\s|[\\\\'\")\`])" \ - 2> >(__zplug::io::log::capture) >/dev/null && + 2> >(__zplug::log::capture::error) >/dev/null && depends+=( "$omz_libs[$lib_f]" ) done done diff --git a/base/utils/shell.zsh b/base/utils/shell.zsh index 03f4389..f7f06e7 100644 --- a/base/utils/shell.zsh +++ b/base/utils/shell.zsh @@ -63,12 +63,6 @@ __zplug::utils::shell::glob2regexp() local -i i=0 local glob="$1" char - if (( $# < 1 )); then - __zplug::io::log::error \ - "too few arguments" - return 1 - fi - printf "^" for ((; i < $#glob; i++)) do @@ -108,7 +102,7 @@ __zplug::utils::shell::sudo() local pw="$ZPLUG_SUDO_PASSWORD" if [[ -z $pw ]]; then - __zplug::io::log::error \ + __zplug::log::write::error \ "ZPLUG_SUDO_PASSWORD: is an invalid value\n" return 1 fi @@ -194,7 +188,7 @@ __zplug::utils::shell::expand_glob() if (( $#matches <= 1 )); then matches=( $( \ zsh -c "$_ZPLUG_CONFIG_SUBSHELL; echo $pattern" \ - 2> >(__zplug::io::log::capture) \ + 2> >(__zplug::log::capture::error) \ ) ) fi @@ -206,7 +200,7 @@ __zplug::utils::shell::eval() local cmd # Report stderr to error log - eval "${=cmd}" 2> >(__zplug::io::log::capture) >/dev/null + eval "${=cmd}" 2> >(__zplug::log::capture::error) >/dev/null return $status } diff --git a/init.zsh b/init.zsh index 0bd8049..f170383 100644 --- a/init.zsh +++ b/init.zsh @@ -15,6 +15,7 @@ source "$ZPLUG_ROOT/autoload/init.zsh" __zplug::base "base/*" __zplug::base "core/*" __zplug::base "io/*" +__zplug::base "log/*" __zplug::base "job/*" __zplug::base "sources/*" __zplug::base "utils/*" diff --git a/test/base/io/log.t b/test/base/io/log.t deleted file mode 100644 index 4132f88..0000000 --- a/test/base/io/log.t +++ /dev/null @@ -1,12 +0,0 @@ -T_SUB "__zplug::io::log::with_json" (( - # skip -)) -T_SUB "__zplug::io::log::level" (( - # skip -)) -T_SUB "__zplug::io::log::new" (( - # skip -)) -T_SUB "__zplug::io::log::capture" (( - # skip -))