Subject: [sup-talk] [PATCH] Make SUP_LOG_LEVEL self-documenting.

From: [email-masked] (Carl Worth)
Date: Wed, 19 Aug 2009 22:25:39 -0700

The idea here is that if someone is looking at the log and not seeing
the information of interest, then the log itself should tell them
how to get more information, (by suggesting to set SUP_LOG_LEVEL
to the next lower level).
---

I'm probably still off as far as standard ruby idioms, (and I'm
probably committing some sup layer violations as well). But hopefully
you get the idea. I went to the log looking for details, couldn't find
them, and had to resort to searching the mailing list for the exact
name of the SUP_LOG_LEVEL variable.

 bin/sup           |    3 +++
 lib/sup/logger.rb |    2 ++
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/bin/sup b/bin/sup
index 3d5b6c1..afe2233 100755
--- a/bin/sup
+++ b/bin/sup
@@ -169,6 +169,9 @@ begin
   lmode.on_kill { Logger.clear! }
   Logger.add_sink lmode
   Logger.force_message "Welcome to Sup! Log level is set to #{Logger.level}."
+  if Logger.LEVELS.index(Logger.level) > 0
+    Logger.force_message "For more verbose logging, restart with SUP_LOG_LEVEL=#{Logger.LEVELS[Logger.LEVELS.index(Logger.level)-1]}."
+  end
 
   debug "initializing inbox buffer"
   imode = InboxMode.new
diff --git a/lib/sup/logger.rb b/lib/sup/logger.rb
index ccaeae0..8567174 100644
--- a/lib/sup/logger.rb
+++ b/lib/sup/logger.rb
@@ -12,6 +12,8 @@ class Logger
 
   LEVELS = %w(debug info warn error) # in order!
 
+  def LEVELS; LEVELS end
+
   def initialize level=nil
     level ||= ENV["SUP_LOG_LEVEL"] || "info"
     @level = LEVELS.index(level) or raise ArgumentError, "invalid log level #{level.inspect}: should be one of #{LEVELS * ', '}"
-- 
1.6.3.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/8eb1635a/attachment.bin>

---

From: [email-masked] (William Morgan)
Date: Sat, 22 Aug 2009 13:25:22 -0700

Reformatted excerpts from Carl Worth's message of 2009-08-19:
> probably committing some sup layer violations as well).

It all looks good except you can use Logger::LEVELS to access the
constants. Then there's no need to write a LEVELS method. If you fix
that I will apply. Thanks!
-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Carl Worth)
Date: Wed, 26 Aug 2009 14:35:25 -0700

> that I will apply. Thanks!

Thanks. I had the distinct feeling I was doing something wrong
there. Here's a corrected version.

-Carl

 bin/sup |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/bin/sup b/bin/sup
index 3d5b6c1..cdf1ff2 100755
--- a/bin/sup
+++ b/bin/sup
@@ -169,6 +169,9 @@ begin
   lmode.on_kill { Logger.clear! }
   Logger.add_sink lmode
   Logger.force_message "Welcome to Sup! Log level is set to #{Logger.level}."
+  if Logger::LEVELS.index(Logger.level) > 0
+    Logger.force_message "For more verbose logging, restart with SUP_LOG_LEVEL=#{Logger::LEVELS[Logger::LEVELS.index(Logger.level)-1]}."
+  end

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090826/3686da0d/attachment.bin>

---

From: [email-masked] (William Morgan)
Date: Mon, 31 Aug 2009 20:06:05 -0700

Applied, thanks!