# HG changeset patch
# User cli
# Date 1250796663 -7200
# Node ID 5a4a41cfc0a3e74802f4ae690bb99e796d949902
# Parent  f2293e8566f52509c147cc204c8fce5c703706c7
Issue #538 fixed.

diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/mlgw/Dispatcher.java
--- a/org/sonews/mlgw/Dispatcher.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/mlgw/Dispatcher.java	Thu Aug 20 21:31:03 2009 +0200
@@ -115,7 +115,7 @@
     }
     else if(fallback)
     {
-      Log.msg("Using fallback recipient discovery for: " + msg.getSubject(), true);
+      Log.get().info("Using fallback recipient discovery for: " + msg.getSubject());
       groups = new ArrayList<String>();
       // Fallback to TO/CC/BCC addresses
       Address[] to = msg.getAllRecipients();
@@ -181,7 +181,7 @@
             groups.append(',');
           }
         }
-        Log.msg("Posting to group " + groups.toString(), true);
+        Log.get().info("Posting to group " + groups.toString());
 
         article.setGroup(groups.toString());
         //article.removeHeader(Headers.REPLY_TO);
@@ -190,14 +190,15 @@
         // Write article to database
         if(updateReq)
         {
-          Log.msg("Updating " + article.getMessageID() + " with additional groups", true);
+          Log.get().info("Updating " + article.getMessageID()
+            + " with additional groups");
           StorageManager.current().delete(article.getMessageID());
           StorageManager.current().addArticle(article);
         }
         else
         {
-          Log.msg("Gatewaying " + article.getMessageID() + " to "
-            + article.getHeader(Headers.NEWSGROUPS)[0], true);
+          Log.get().info("Gatewaying " + article.getMessageID() + " to "
+            + article.getHeader(Headers.NEWSGROUPS)[0]);
           StorageManager.current().addArticle(article);
           Stats.getInstance().mailGatewayed(
             article.getHeader(Headers.NEWSGROUPS)[0]);
@@ -213,7 +214,7 @@
           buf.append(toa.toString());
         }
         buf.append(" " + article.getHeader(Headers.LIST_POST)[0]);
-        Log.msg("No group for" + buf.toString(), false);
+        Log.get().warning("No group for" + buf.toString());
       }
       return posted;
     }
@@ -237,7 +238,7 @@
 
     if(rcptAddresses == null || rcptAddresses.size() == 0)
     {
-      Log.msg("No ML-address for " + group + " found.", false);
+      Log.get().warning("No ML-address for " + group + " found.");
       return;
     }
 
@@ -271,8 +272,8 @@
       smtpTransport.close();
 
       Stats.getInstance().mailGatewayed(group);
-      Log.msg("MLGateway: Mail " + article.getHeader("Subject")[0]
-        + " was delivered to " + rcptAddress + ".", true);
+      Log.get().info("MLGateway: Mail " + article.getHeader("Subject")[0]
+        + " was delivered to " + rcptAddress + ".");
     }
   }
   
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/mlgw/MailPoller.java
--- a/org/sonews/mlgw/MailPoller.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/mlgw/MailPoller.java	Thu Aug 20 21:31:03 2009 +0200
@@ -61,7 +61,7 @@
   @Override
   public void run()
   {
-    Log.msg("Starting Mailinglist Poller...", false);
+    Log.get().info("Starting Mailinglist Poller...");
     int errors = 0;
     while(isRunning() && errors < 5)
     {
@@ -119,7 +119,7 @@
       }
       catch(NoSuchProviderException ex)
       {
-        Log.msg(ex.toString(), false);
+        Log.get().severe(ex.toString());
         shutdown();
       }
       catch(AuthenticationFailedException ex)
@@ -145,7 +145,7 @@
         errors++;
       }
     }
-    Log.msg("MailPoller exited.", false);
+    Log.get().severe("MailPoller exited.");
   }
   
 }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/storage/Article.java
--- a/org/sonews/storage/Article.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/storage/Article.java	Thu Aug 20 21:31:03 2009 +0200
@@ -139,8 +139,10 @@
       // Unknown content is probably a malformed mail we should skip.
       // On the other hand we produce an inconsistent mail mirror, but no
       // mail system must transport invalid content.
-      Log.msg("Skipping message due to unknown content. Throwing exception...", true);
-      throw new MessagingException("Unknown content: " + content);
+      Log.get().severe("Skipping message due to unknown content. Throwing exception...");
+      MessagingException ex = new MessagingException("Unknown content: " + content);
+      Log.get().throwing("Article.java", "<init>", ex);
+      throw ex;
     }
     
     // Validate headers
@@ -264,8 +266,8 @@
     }
     catch(Exception ex)
     {
-      Log.msg(ex.getMessage(), false);
-      Log.msg("Article.getBodyCharset(): Unknown charset: " + charsetName, false);
+      Log.get().severe(ex.getMessage());
+      Log.get().severe("Article.getBodyCharset(): Unknown charset: " + charsetName);
     }
     return charset;
   }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/storage/Group.java
--- a/org/sonews/storage/Group.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/storage/Group.java	Thu Aug 20 21:31:03 2009 +0200
@@ -65,7 +65,7 @@
     }
     catch(StorageBackendException ex)
     {
-      Log.msg(ex.getMessage(), false);
+      Log.get().severe(ex.getMessage());
       return null;
     }
   }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/storage/impl/JDBCDatabase.java
--- a/org/sonews/storage/impl/JDBCDatabase.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/storage/impl/JDBCDatabase.java	Thu Aug 20 21:31:03 2009 +0200
@@ -121,7 +121,7 @@
       this.conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
       if(this.conn.getTransactionIsolation() != Connection.TRANSACTION_SERIALIZABLE)
       {
-        Log.msg("Warning: Database is NOT fully serializable!", false);
+        Log.get().warning("Database is NOT fully serializable!");
       }
 
       // Prepare statements for method addArticle()
@@ -360,7 +360,7 @@
       }
       catch(SQLException ex2)
       {
-        Log.msg("Rollback of addArticle() failed: " + ex2, false);
+        Log.get().severe("Rollback of addArticle() failed: " + ex2);
       }
       
       try
@@ -369,7 +369,7 @@
       }
       catch(SQLException ex2)
       {
-        Log.msg("setAutoCommit(true) of addArticle() failed: " + ex2, false);
+        Log.get().severe("setAutoCommit(true) of addArticle() failed: " + ex2);
       }
 
       restartConnection(ex);
@@ -1486,7 +1486,7 @@
       }
       else
       {
-        Log.msg("Warning: Count on postings return nothing!", true);
+        Log.get().warning("Count on postings return nothing!");
         return 0;
       }
     }
@@ -1696,8 +1696,8 @@
     throws StorageBackendException
   {
     restarts++;
-    Log.msg(Thread.currentThread() 
-      + ": Database connection was closed (restart " + restarts + ").", false);
+    Log.get().severe(Thread.currentThread()
+      + ": Database connection was closed (restart " + restarts + ").");
     
     if(restarts >= MAX_RESTARTS)
     {
@@ -1715,7 +1715,7 @@
     }
     catch(InterruptedException ex)
     {
-      Log.msg("Interrupted: " + ex.getMessage(), false);
+      Log.get().warning("Interrupted: " + ex.getMessage());
     }
     
     // Try to properly close the old database connection
@@ -1728,7 +1728,7 @@
     }
     catch(SQLException ex)
     {
-      Log.msg(ex.getMessage(), true);
+      Log.get().warning(ex.getMessage());
     }
     
     try
@@ -1738,7 +1738,7 @@
     }
     catch(SQLException ex)
     {
-      Log.msg(ex.getMessage(), true);
+      Log.get().warning(ex.getMessage());
       restartConnection(ex);
     }
   }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/util/Log.java
--- a/org/sonews/util/Log.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/util/Log.java	Thu Aug 20 21:31:03 2009 +0200
@@ -39,8 +39,10 @@
   {
     Logger mainLogger = Logger.getLogger(MAIN);
     StreamHandler handler = new StreamHandler(System.out, new SimpleFormatter());
-    handler.setLevel(Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO")));
+    Level level = Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO"));
+    handler.setLevel(level);
     mainLogger.addHandler(handler);
+    mainLogger.setLevel(level);
     LogManager.getLogManager().addLogger(mainLogger);
   }
 
@@ -51,7 +53,10 @@
 
   public static Logger get(String name)
   {
-    return LogManager.getLogManager().getLogger(name);
+    Level level = Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO"));
+    Logger logger = LogManager.getLogManager().getLogger(name);
+    logger.setLevel(level);
+    return logger;
   }
 
 }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/util/Purger.java
--- a/org/sonews/util/Purger.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/util/Purger.java	Thu Aug 20 21:31:03 2009 +0200
@@ -63,7 +63,7 @@
     }
     catch(InterruptedException ex)
     {
-      Log.msg("Purger interrupted: " + ex, true);
+      Log.get().warning("Purger interrupted: " + ex);
     }
   }
 
@@ -84,14 +84,14 @@
         if(ids.size() == 0)
         {
           StorageManager.current().purgeGroup(group);
-          Log.msg("Group " + group.getName() + " purged.", true);
+          Log.get().info("Group " + group.getName() + " purged.");
         }
 
         for(int n = 0; n < ids.size() && n < 10; n++)
         {
           Article art = StorageManager.current().getArticle(ids.get(n), group.getInternalID());
           StorageManager.current().delete(art.getMessageID());
-          Log.msg("Article " + art.getMessageID() + " purged.", true);
+          Log.get().info("Article " + art.getMessageID() + " purged.");
         }
       }
     }
@@ -107,7 +107,7 @@
 
     if(lifetime > 0 || articleMaximum < Stats.getInstance().getNumberOfNews())
     {
-      Log.msg("Purging old messages...", true);
+      Log.get().info("Purging old messages...");
       String mid = StorageManager.current().getOldestArticle();
       if (mid == null) // No articles in the database
       {
@@ -123,7 +123,7 @@
       }
       catch (IllegalArgumentException ex)
       {
-        Log.msg("Could not parse date string: " + dateStr + " " + ex, true);
+        Log.get().warning("Could not parse date string: " + dateStr + " " + ex);
       }
 
       // Should we delete the message because of its age or because the
@@ -141,7 +141,7 @@
     }
     else
     {
-      Log.msg("Lifetime purger is disabled", true);
+      Log.get().info("Lifetime purger is disabled");
       Thread.sleep(1000 * 60 * 30); // Wait 30 minutes
     }
   }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/util/Stats.java
--- a/org/sonews/util/Stats.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/util/Stats.java	Thu Aug 20 21:31:03 2009 +0200
@@ -76,7 +76,7 @@
       }
       else
       {
-        Log.msg("Group " + groupname + " does not exist.", true);
+        Log.get().info("Group " + groupname + " does not exist.");
       }
     }
   }
diff -r f2293e8566f5 -r 5a4a41cfc0a3 org/sonews/util/io/ArticleReader.java
--- a/org/sonews/util/io/ArticleReader.java	Thu Aug 20 18:41:21 2009 +0200
+++ b/org/sonews/util/io/ArticleReader.java	Thu Aug 20 21:31:03 2009 +0200
@@ -95,7 +95,7 @@
           buf.write(10);
           if(buf.size() > maxSize)
           {
-            Log.msg("Skipping message that is too large: " + buf.size(), false);
+            Log.get().warning("Skipping message that is too large: " + buf.size());
             return null;
           }
         }
@@ -104,7 +104,7 @@
       }
       else
       {
-        Log.msg("ArticleReader: " + line, false);
+        Log.get().warning("ArticleReader: " + line);
         return null;
       }
     }