]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
More logging work, also rewriting printstacktrace to logger.*
authorJan-Pascal van Best <janpascal@vanbest.org>
Sat, 28 Apr 2012 12:31:07 +0000 (14:31 +0200)
committerJan-Pascal van Best <janpascal@vanbest.org>
Sat, 28 Apr 2012 12:31:07 +0000 (14:31 +0200)
src/main/java/org/vanbest/xmltv/AbstractEPGSource.java
src/main/java/org/vanbest/xmltv/Config.java
src/main/java/org/vanbest/xmltv/EPGSourceFactory.java
src/main/java/org/vanbest/xmltv/Main.java
src/main/java/org/vanbest/xmltv/ProgrammeCache.java
src/main/java/org/vanbest/xmltv/RTL.java

index 26cf99eec8078f3d4b2987fc89f6b19e50601d21..31eb9306ace1e77e4691920d2c7fd1536f632601 100644 (file)
@@ -69,7 +69,7 @@ public abstract class AbstractEPGSource implements EPGSource {
                                }
                                if (count>=MAX_FETCH_TRIES) { 
                                        stats.fetchErrors++;
-                                       if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                                       logger.debug("Error getting progrm data from url", e);
                                        throw new Exception("Error getting program data from url " + url, e);
                                }
                        }
index 6890ba7f9f0654270d0275f03500e38d66597f84..ce883580f2ef69fd2f58c813df07ea234cfdc9e7 100644 (file)
@@ -71,7 +71,8 @@ public class Config {
         try {
             configProp.load(in);
         } catch (IOException e) {
-            e.printStackTrace();
+            logger.warn("Error reading application properties from tv_grab_nl_java.properties resource");
+            logger.debug("stack trace: ", e);
         }
         project_version=configProp.getProperty("project.version");
         build_time=configProp.getProperty("build.time");
@@ -294,7 +295,7 @@ public class Config {
                                }
                        }
                } catch (IOException e) {
-                       e.printStackTrace();
+                       logger.debug("stack trace:", e);
                        logger.warn("Error reading configuration file, continuing with empty configuration");
                        return getDefaultConfig();
                }
index bafde354b05e9525dd6a9b7f9d8f19c2d97857a3..3597977ea7201e5ee2ee4dbb62a8bdb60fdb0e43 100644 (file)
@@ -13,12 +13,16 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.log4j.Logger;
+
 public class EPGSourceFactory {
        private static Map<String,Integer> ids = new HashMap<String,Integer>();
        private static Map<Integer,Class<EPGSource>> classes = new HashMap<Integer,Class<EPGSource>>();
        private static Map<Integer,String> names = new HashMap<Integer,String>();
        private static boolean initialised=false;
        private static List<Integer> sources=new ArrayList<Integer>();
+       static Logger logger = Logger.getLogger(EPGSourceFactory.class);
+
 
        static void init() {
                if(initialised) return;
@@ -28,7 +32,7 @@ public class EPGSourceFactory {
         try {
             configProp.load(in);
         } catch (IOException e) {
-            e.printStackTrace();
+            logger.warn("Error reading application properties resource", e);
         }
         for(int source=1; ; source++) {
                String name = configProp.getProperty("org.vanbest.xmltv.epgsource.impl."+source);
@@ -43,21 +47,8 @@ public class EPGSourceFactory {
                                names.put(source,sourceName);
                                ids.put(sourceName,source);
                                sources.add(source);
-                       } catch (ClassNotFoundException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       } catch (SecurityException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       } catch (NoSuchFieldException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       } catch (IllegalArgumentException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       } catch (IllegalAccessException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
+                       } catch (Exception e) {
+                               logger.error("Error reading EPG Source class "+name, e);
                        }
         }
         initialised=true;
@@ -76,24 +67,8 @@ public class EPGSourceFactory {
                try {
                        constructor = classes.get(source).getConstructor(Integer.TYPE,Config.class);
                        return constructor.newInstance(source, config);
-               } catch (NoSuchMethodException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (SecurityException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (InstantiationException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (IllegalAccessException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (IllegalArgumentException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (InvocationTargetException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+               } catch (Exception e) {
+                       logger.error("Error instantiating EPG source "+classes.get(source), e);
                }
                return null;
        }
index 6432b0fa34cb97ddc6304a6f67ff6f36866b0c36..db0d123307ee12899429ffdc9232a887976945e6 100644 (file)
@@ -264,11 +264,9 @@ public class Main {
                        config.writeConfig(configFile);
                        logger.info("Configuration file written to " + configFile.getPath());
                } catch (FileNotFoundException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       logger.warn("File not found trying to write config file to "+configFile.getPath(), e);
                } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       logger.warn("IO Exception trying to write config file to "+configFile.getPath(), e);
                }
        }
 
@@ -419,8 +417,8 @@ public class Main {
                        try {
                                configure();
                        } catch (IOException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
+                               logger.warn("Exception during configure");
+                               logger.debug("Stack trace: ", e);
                        }
                        System.exit(0);
                }
index 33bd0c23e73916eafde2c60c954bdbb85f5014a5..796de588134c5e27a96821d007f11226368ff363 100644 (file)
@@ -59,7 +59,7 @@ public class ProgrammeCache {
                        db = DriverManager.getConnection(config.cacheDbHandle, config.cacheDbUser, config.cacheDbPassword);
                        /* Test for upgrade path from legacy database
                        Statement stat = db.createStatement();
-                       System.out.println("Dropping old table");
+                       .println("Dropping old table");
                        stat.execute("DROP TABLE IF EXISTS cache");
                        System.out.println("Creating new table");
                        stat.execute("CREATE CACHED TABLE IF NOT EXISTS cache (id VARCHAR(64) PRIMARY KEY, date DATE, programme OTHER)");
@@ -161,8 +161,8 @@ public class ProgrammeCache {
                        }
                } catch (SQLException e) {
                        if (!config.quiet) {
-                               System.out.println("Error fetching programme ("+source+","+id+") from cache");
-                               if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                               logger.warn("Error fetching programme ("+source+","+id+") from cache");
+                               logger.debug("stack trace: ", e);
                        }
                        return null;
                }
@@ -174,8 +174,8 @@ public class ProgrammeCache {
                        removeStatement.setString(2, id);
                        removeStatement.execute();
                } catch (SQLException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       logger.warn("Exception trying to remove item "+id+" from source "+source+" from cache");
+                       logger.debug("Stack trace: ", e);
                }
        }
 
@@ -208,7 +208,6 @@ public class ProgrammeCache {
                        }
                        stat.close();
                } catch (SQLException e) {
-                       // TODO Auto-generated catch block
                        logger.debug("stack trace:", e);
                }
        }
@@ -218,10 +217,11 @@ public class ProgrammeCache {
                try {
                        int count = clearStatement.executeUpdate();
                        if (!config.quiet && count>0) {
-                               System.out.println("Cleared " + count + " entries from cache");
+                               logger.info("Cleared " + count + " entries from cache");
                        }
                } catch (SQLException e) {
-                       if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                       logger.warn("Failed to clear cache");
+                       logger.debug("Stack trace: ", e);
                }
        }
 
@@ -231,10 +231,11 @@ public class ProgrammeCache {
                        clearSourceStatement.setInt(1, source);
                        int count = clearSourceStatement.executeUpdate();
                        if (!config.quiet && count>0) {
-                               System.out.println("Cleared " + count + " entries from cache for source " + source);
+                               logger.info("Cleared " + count + " entries from cache");
                        }
                } catch (SQLException e) {
-                       if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                       logger.warn("Failed to clear cache");
+                       logger.debug("Stack trace: ", e);
                }
        }
 
@@ -249,8 +250,8 @@ public class ProgrammeCache {
                                clearSourceStatement.close();
                                db.close();
                        } catch (SQLException e) {
-                               // TODO Auto-generated catch block
-                               if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                               logger.warn("Error closing cache database connection");
+                               logger.debug("Stack trace: ", e);
                        }
                }
        }
index ce79c31201a78ae8ccf5a2c73cb258d8c1ffb9e8..2d546efd1da9f4a19ff28ead7bc5fb0c64794552 100644 (file)
@@ -122,15 +122,13 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
                try {\r
                        url = new URL(programme_url+"1");\r
                } catch (MalformedURLException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
+                       logger.error("Exception creating RTL channel list url", e);\r
                }\r
                Document xml = null;\r
                try {\r
                        xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream());\r
                } catch (Exception e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
+                       logger.error("Exception reading info from "+url+" and transforming to XML", e);\r
                }\r
                Element root = xml.getDocumentElement();\r
                String json = root.getTextContent();\r