[darcs-devel] Logging

Jason Dagit dagit at codersbase.com
Sun Sep 10 16:12:28 PDT 2006


Hello,

I was working on the darcs source today and I realized that in a lot
of ways the current logging output is poor.  Mostly we don't have
enough of it.

Here are some changes I started making:

1) In DarcsFlags change Verbose | Quiet to Verbose Int.  The
understanding would be that Verbose 0 == Quiet, Verbose 3 == standard
verbosity and Verbose 9 == Highest verbosity.  On the commandline
--verbose would be equivalent to -v3.

2) In DarcsUtils define the following functions:
---------------------------
-- Prints the message if the verbosity set in the current options
-- is greater than or equal to the verbosity level.
-- 
-- For example,
-- logStr [Verbose 3] 3 "Standard verbosity"
-- then we would see, "Standard verbosity" on stdout.
--
-- Or, in the case of 'quiet' mode:
-- logStr [Verbose 0] 3 "This won't produce output"
logStr :: [DarcsFlag] -- options
    -> Int         -- the verbosity level
    -> String      -- message
    -> IO ()
logStr opts n mesg = logPutStr mesg level
  where
  logPutStr s l = when (n <= l) (putStr s >> hFlush stdout)
  level = getVerbosity opts

-- Varation of 'logStr' that adds a newline
logStrLn :: [DarcsFlag] -> Int -> String -> IO ()
logStrLn opts n mesg = logStr opts n (mesg++"\n")

-- Checks if a DarcsFlag is the verbosity flag
isVerbose :: DarcsFlag -> Bool
isVerbose (Verbose _) = True
isVerbose _           = False

-- Here we enforce 3 as the default verbosity
getVerbosity :: [DarcsFlag] -> Int
getVerbosity opts = maybe 3 verbosity (find isVerbose opts)
  where
  verbosity (Verbose v) = v
  verbosity _           = undefined -- can't happen because we 'find' first
-------------------------------

It seems that logging is usually done one of three ways:
  (a) Simple check like (Verbose `elem` opts) and then putStrLn is called
  (b) Output on stdout for Verbose and separate output on stderr for Quiet
  (c) Conditional formatting depending on Verbose

I was going through the code and trying to replace all the current
logging with equivalent calls to getVerbosity, logStr and logStrLn.
My first pass is to just get the code to compile with the new logging
code then to refactor the logging and eventually add more output.

What do people think?  What do you like and dislike about this
proposal?  Suggestions on how to unify things?  Should negative
verbosity levels go to stderr?  For example,
logStr opts (-1) "This is an error."

I think having different levels of verbosity gives us a lot more
freedom to 'log everything' and then control how much we're seeing.

Thanks,
Jason




More information about the darcs-devel mailing list