From 658ec4e4a73aa0dcf186c7b74a89ce678daf4950 Mon Sep 17 00:00:00 2001
From: Kaleb Elwert <belak@coded.io>
Date: Wed, 7 Feb 2018 13:38:54 -0800
Subject: [PATCH 1/3] Add zdebuglog for basic debug logging and profiling

---
 init.zsh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/init.zsh b/init.zsh
index 99254bdb..2c0797a8 100644
--- a/init.zsh
+++ b/init.zsh
@@ -17,6 +17,19 @@ if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then
 fi
 unset min_zsh_version
 
+typeset -F SECONDS
+
+function zdebuglog {
+  if ! zstyle -t ":prezto" debug; then
+    echo no debug
+    return
+  fi
+
+  local format="$1"
+  shift
+  printf "[%f] $format\n" $SECONDS "$@"
+}
+
 # zprezto convenience updater
 # The function is surrounded by ( ) instead of { } so it starts in a subshell
 # and won't affect the environment of the calling shell
@@ -93,7 +106,9 @@ function pmodload {
 
   # Load Prezto modules.
   for pmodule in "$pmodules[@]"; do
+    zdebuglog "Started loading %q" $pmodule
     if zstyle -t ":prezto:module:$pmodule" loaded 'yes' 'no'; then
+      zdebuglog "Module %q already loaded" $pmodule
       continue
     else
       locations=(${pmodule_dirs:+${^pmodule_dirs}/$pmodule(-/FN)})
@@ -131,6 +146,7 @@ function pmodload {
 
       if (( $? == 0 )); then
         zstyle ":prezto:module:$pmodule" loaded 'yes'
+        zdebuglog "Module %q loaded" $pmodule
       else
         # Remove the $fpath entry.
         fpath[(r)${pmodule_location}/functions]=()
@@ -148,6 +164,7 @@ function pmodload {
           done
         }
 
+        zdebuglog "Module %q failed to load" $pmodule
         zstyle ":prezto:module:$pmodule" loaded 'no'
       fi
     fi

From 6ab2cc012e95425fa0108a49d5db220c04ea6f0b Mon Sep 17 00:00:00 2001
From: Kaleb Elwert <belak@coded.io>
Date: Mon, 12 Feb 2018 15:14:08 -0800
Subject: [PATCH 2/3] zdebuglog -> pdebuglog

---
 init.zsh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/init.zsh b/init.zsh
index 2c0797a8..cefd37c8 100644
--- a/init.zsh
+++ b/init.zsh
@@ -19,7 +19,7 @@ unset min_zsh_version
 
 typeset -F SECONDS
 
-function zdebuglog {
+function pdebuglog {
   if ! zstyle -t ":prezto" debug; then
     echo no debug
     return
@@ -106,9 +106,9 @@ function pmodload {
 
   # Load Prezto modules.
   for pmodule in "$pmodules[@]"; do
-    zdebuglog "Started loading %q" $pmodule
+    pdebuglog "Started loading %q" $pmodule
     if zstyle -t ":prezto:module:$pmodule" loaded 'yes' 'no'; then
-      zdebuglog "Module %q already loaded" $pmodule
+      pdebuglog "Module %q already loaded" $pmodule
       continue
     else
       locations=(${pmodule_dirs:+${^pmodule_dirs}/$pmodule(-/FN)})
@@ -146,7 +146,7 @@ function pmodload {
 
       if (( $? == 0 )); then
         zstyle ":prezto:module:$pmodule" loaded 'yes'
-        zdebuglog "Module %q loaded" $pmodule
+        pdebuglog "Module %q loaded" $pmodule
       else
         # Remove the $fpath entry.
         fpath[(r)${pmodule_location}/functions]=()
@@ -164,7 +164,7 @@ function pmodload {
           done
         }
 
-        zdebuglog "Module %q failed to load" $pmodule
+        pdebuglog "Module %q failed to load" $pmodule
         zstyle ":prezto:module:$pmodule" loaded 'no'
       fi
     fi

From 3524cc20f08a6b662c2a983743ec02adbcf877a2 Mon Sep 17 00:00:00 2001
From: Kaleb Elwert <belak@coded.io>
Date: Mon, 12 Feb 2018 15:16:21 -0800
Subject: [PATCH 3/3] Add comments for pdebuglog

---
 init.zsh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/init.zsh b/init.zsh
index cefd37c8..ae968723 100644
--- a/init.zsh
+++ b/init.zsh
@@ -17,11 +17,12 @@ if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then
 fi
 unset min_zsh_version
 
+# Change the resolution of the SECONDS variable to be more useful for debugging.
 typeset -F SECONDS
 
+# logging convenience, mostly meant for debugging performance issues.
 function pdebuglog {
   if ! zstyle -t ":prezto" debug; then
-    echo no debug
     return
   fi