}
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);
}
}
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");
}
}
} catch (IOException e) {
- e.printStackTrace();
+ logger.debug("stack trace:", e);
logger.warn("Error reading configuration file, continuing with empty configuration");
return getDefaultConfig();
}
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;
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);
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;
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;
}
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);
}
}
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);
}
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)");
}
} 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;
}
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);
}
}
}
stat.close();
} catch (SQLException e) {
- // TODO Auto-generated catch block
logger.debug("stack trace:", e);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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