--- pungi-original	2007-05-03 18:34:32.000000000 +0200
+++ pungi-JG	2007-05-04 17:36:38.000000000 +0200
@@ -16,6 +16,7 @@
 import pypungi.gather
 import pypungi.pungi
 import yum
+import logging
 
 from ConfigParser import SafeConfigParser
 
@@ -79,6 +80,19 @@
 
     destdir = config.get('default', 'destdir')
 
+    if not config.has_option('default', 'quiet'):quiet=False
+    else:quiet=True
+    config.set('default','quiet',str(quiet))
+    
+    config.set('default','verbose',str(opts.verbose))
+    
+    # initialize logging. 
+    initLogger(config.get('default', 'destdir'),
+               '%s.%s.log' % (config.get('default', 'flavor'), config.get('default', 'arch')),
+               quiet=quiet,
+               useVerboseMode= opts.verbose)
+    log = logging.getLogger("pungi")
+
     if not os.path.exists(destdir):
         try:
             os.makedirs(destdir)
@@ -157,6 +171,8 @@
           help="Flag to enable processing the SplitTree stage")
         parser.add_option("-I", action="store_true", default=False, dest="do_createiso",
           help="Flag to enable processing the CreateISO stage")
+        parser.add_option("-v", action="store_true", default=False, dest="verbose",
+          help="Flag to enable verbose mode")
 
 
         (opts, args) = parser.parse_args()
@@ -180,4 +195,31 @@
         manifestfile.close()
         return pkglist
 
+    def initLogger(path, filename, quiet=True, useVerboseMode=False):
+        """Initialize the log stuff so other files can use it.
+    
+        path - Is the directory where the log will be located
+        filename - Is the log files name
+        useLogFile - Whether to log to the file or not
+        useVerboseMode - Whether to output stuff to pungis stdout
+        """
+        logger = logging.getLogger("pungi")
+        if not quiet:
+            logdir = os.path.join(path , 'logs')
+            if not os.path.exists(logdir):
+                os.makedirs(logdir)
+            logfile = os.path.join(logdir, filename)
+    
+            fileHandler = logging.FileHandler(logfile)
+            fileHandler.setLevel(logging.DEBUG)
+            logger.addHandler(fileHandler) 
+        
+        if useVerboseMode:
+            stdoutHandler = logging.StreamHandler(sys.stdout)
+            stdoutHandler.setLevel(logging.INFO)
+            logger.addHandler(stdoutHandler)
+        
+        logger.setLevel(logging.DEBUG)
+        if quiet and not useVerboseMode:logger.disabled=1
+
     main()
