Mercurial > dive4elements > framework
changeset 17:5a6b6a3debc7
Integrated logging into artifact database.
artifacts/trunk@33 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 08 Sep 2009 06:29:52 +0000 |
parents | 635310c6a20e |
children | 63a8aa276693 |
files | Changelog TODO artifact-database/pom.xml artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java |
diffstat | 9 files changed, 86 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/Changelog Mon Sep 07 13:22:48 2009 +0000 +++ b/Changelog Tue Sep 08 06:29:52 2009 +0000 @@ -1,9 +1,23 @@ +2009-09-08 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java: + Integrated log4j + + * artifact-database/pom.xml: Added dependency to log4j + + * TODO: Removed remark to integrate logging. + 2009-09-07 Tim Englich <tim.englich@intevation.de> - * src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java: edited - Bug fixed in XPath Expression. Now the Nodes and not the Text of the Nodes will - be used instantiating the ArtifactFactory. - + * src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java: edited + Bug fixed in XPath Expression. Now the Nodes and not the Text of the Nodes will + be used instantiating the ArtifactFactory. + 2009-09-07 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
--- a/TODO Mon Sep 07 13:22:48 2009 +0000 +++ b/TODO Tue Sep 08 06:29:52 2009 +0000 @@ -1,5 +1,4 @@ TODO: - * integrate logging into artifact database. * Document the XML of the configuration file. * Implement a "killer" thread in artifact database which periodically kills all outdated artifacts.
--- a/artifact-database/pom.xml Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/pom.xml Tue Sep 08 06:29:52 2009 +0000 @@ -61,5 +61,10 @@ <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>[1.2,)</version> + </dependency> </dependencies> </project>
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Tue Sep 08 06:29:52 2009 +0000 @@ -25,11 +25,15 @@ import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.Artifact; +import org.apache.log4j.Logger; + /** * @author Sascha L. Teichmann */ public class Backend { + private static Logger logger = Logger.getLogger(Backend.class); + public static final String SQL_NEXT_ID = SQL.get("artifacts.id.nextval"); @@ -140,6 +144,7 @@ return bos.toByteArray(); } catch (IOException ioe) { + logger.error(ioe.getLocalizedMessage(), ioe); throw new RuntimeException(ioe); } } @@ -155,6 +160,7 @@ uuid = UUID.fromString(idenitfier); } catch (IllegalArgumentException iae) { + logger.warn(iae.getLocalizedMessage()); return null; } @@ -219,7 +225,7 @@ return new ArtifactProxy(original, id, false); } catch (SQLException sqle) { - sqle.printStackTrace(System.err); + logger.error(sqle.getLocalizedMessage(), sqle); } finally { if (load_result != null) { @@ -250,13 +256,13 @@ return (Artifact)ois.readObject(); } catch (IOException ioe) { - ioe.printStackTrace(System.err); + logger.error(ioe.getLocalizedMessage(), ioe); } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(System.err); + logger.error(cnfe.getLocalizedMessage(), cnfe); } catch (ClassCastException cce) { - cce.printStackTrace(System.err); + logger.error(cce.getLocalizedMessage(), cce); } finally { if (ois != null) { @@ -269,7 +275,7 @@ } protected void artifactOutdated(int id) { - System.err.println("artifactOutdated: id = " + id); + logger.info("artifactOutdated: id = " + id); } protected int insertDatabase(UUID uuid, Long ttl) { @@ -316,7 +322,7 @@ } } catch (SQLException sqle) { - sqle.printStackTrace(System.err); + logger.error(sqle.getLocalizedMessage(), sqle); } finally { if (res_id != null) { @@ -340,7 +346,7 @@ } public void touch(ArtifactProxy proxy) { - System.err.println("touch: " + proxy); + logger.info("touch: " + proxy); if (proxy.isUnwritten()) { store(proxy); return; @@ -362,7 +368,7 @@ } } catch (SQLException sqle) { - sqle.printStackTrace(System.err); + logger.error(sqle.getLocalizedMessage(), sqle); } finally { if (stmnt_touch != null) { @@ -377,7 +383,7 @@ } public void store(ArtifactProxy proxy) { - System.err.println("store: " + proxy); + logger.info("store: " + proxy); Connection connection = null; PreparedStatement stmnt_update = null; DataSource dataSource = DBConnection.getDataSource(); @@ -396,7 +402,7 @@ } } catch (SQLException sqle) { - sqle.printStackTrace(System.err); + logger.error(sqle.getLocalizedMessage(), sqle); } finally { if (stmnt_update != null) {
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Tue Sep 08 06:29:52 2009 +0000 @@ -20,11 +20,15 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathConstants; +import org.apache.log4j.Logger; + /** * @author Sascha L. Teichmann */ public final class Config { + private static Logger logger = Logger.getLogger(Config.class); + public static final String CONFIG_PROPERTY = "artifact.database.config"; public static final String CONFIG_DEFAULT = "artifactdb-conf.xml"; @@ -46,7 +50,7 @@ System.getProperty(CONFIG_PROPERTY, CONFIG_DEFAULT)); if (!file.canRead() && !file.isFile()) { - System.err.println("ERROR: cannot read config file '" + logger.error("Cannot read config file '" + file + "'."); return null; } @@ -57,18 +61,13 @@ return factory.newDocumentBuilder().parse(file); } catch (SAXException se) { - System.err.println("ERROR: while processing XML file '" - + file + "'"); - se.printStackTrace(System.err); + logger.error(se.getLocalizedMessage(), se); } catch (ParserConfigurationException pce) { - System.err.println("ERROR: with XML configuration"); - pce.printStackTrace(System.err); + logger.error(pce.getLocalizedMessage(), pce); } catch (IOException ioe) { - System.err.println("ERROR: I/O while processing file '" - + file + "'"); - ioe.printStackTrace(System.err); + logger.error(ioe.getLocalizedMessage()); } return null; @@ -88,7 +87,7 @@ return xpath.evaluate(query, root, returnType); } catch (XPathExpressionException xpee) { - xpee.printStackTrace(System.err); + logger.error(xpee.getLocalizedMessage(), xpee); } return null;
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifact.java Tue Sep 08 06:29:52 2009 +0000 @@ -7,12 +7,16 @@ import de.intevation.artifacts.Artifact; +import org.apache.log4j.Logger; + /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class DefaultArtifact implements Artifact { + private static Logger logger = Logger.getLogger(DefaultArtifact.class); + protected String identifier; public DefaultArtifact() { @@ -26,7 +30,7 @@ .newDocument(); } catch (ParserConfigurationException pce) { - pce.printStackTrace(System.err); + logger.error(pce.getLocalizedMessage(), pce); } return null; }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java Tue Sep 08 06:29:52 2009 +0000 @@ -6,9 +6,17 @@ import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.Artifact; +import org.apache.log4j.Logger; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ public class DefaultArtifactFactory implements ArtifactFactory { + private static Logger logger = + Logger.getLogger(DefaultArtifactFactory.class); + public static final String XPATH_TTL = "@ttl"; public static final String XPATH_NAME = "@name"; public static final String XPATH_DESCRIPTION = "@description"; @@ -50,13 +58,13 @@ return artifact; } catch (InstantiationException ie) { - ie.printStackTrace(System.err); + logger.error(ie.getLocalizedMessage(), ie); } catch (IllegalAccessException iae) { - iae.printStackTrace(System.err); + logger.error(iae.getLocalizedMessage(), iae); } catch (ClassCastException cce) { - cce.printStackTrace(System.err); + logger.error(cce.getLocalizedMessage(), cce); } return null; @@ -70,7 +78,7 @@ ttl = Long.valueOf(ttlString); } catch (NumberFormatException nfe) { - nfe.printStackTrace(System.err); + logger.warn("'" + ttlString + "' is not an integer."); } } @@ -87,7 +95,7 @@ artifactClass = Class.forName(artifact); } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(System.err); + logger.error(cnfe.getLocalizedMessage(), cnfe); } if (artifactClass == null) {
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Tue Sep 08 06:29:52 2009 +0000 @@ -8,6 +8,8 @@ import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.ArtifactContextFactory; +import org.apache.log4j.Logger; + /** * Bootstrap facility for the global context and the artifact factories. * @@ -15,6 +17,8 @@ */ public class FactoryBootstrap { + private static Logger logger = Logger.getLogger(FactoryBootstrap.class); + public static final String CONTEXT_FACTORY = "/artifact-database/factories/context-factory/text()"; @@ -42,16 +46,16 @@ factory = (ArtifactContextFactory)clazz.newInstance(); } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(System.err); + logger.error(cnfe.getLocalizedMessage(), cnfe); } catch (InstantiationException ie) { - ie.printStackTrace(System.err); + logger.error(ie.getLocalizedMessage(), ie); } catch (ClassCastException cce) { - cce.printStackTrace(System.err); + logger.error(cce.getLocalizedMessage(), cce); } catch (IllegalAccessException iae) { - iae.printStackTrace(System.err); + logger.error(iae.getLocalizedMessage(), iae); } if (factory == null) { @@ -67,7 +71,7 @@ NodeList nodes = Config.getNodeSetXPath(ARTIFACT_FACTORIES); if (nodes == null) { - System.err.println("ERROR: no factories found"); + logger.warn("No factories found"); return; } @@ -83,16 +87,16 @@ factory = (ArtifactFactory)clazz.newInstance(); } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(System.err); + logger.error(cnfe.getLocalizedMessage(), cnfe); } catch (InstantiationException ie) { - ie.printStackTrace(System.err); + logger.error(ie.getLocalizedMessage(), ie); } catch (ClassCastException cce) { - cce.printStackTrace(System.err); + logger.error(cce.getLocalizedMessage(), cce); } catch (IllegalAccessException iae) { - iae.printStackTrace(System.err); + logger.error(iae.getLocalizedMessage(), iae); } if (factory != null) {
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java Mon Sep 07 13:22:48 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/SQL.java Tue Sep 08 06:29:52 2009 +0000 @@ -5,11 +5,15 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.log4j.Logger; + /** * @author Sascha L. Teichmann */ public final class SQL { + private static Logger logger = Logger.getLogger(SQL.class); + private SQL() { } @@ -35,19 +39,18 @@ in = SQL.class.getResourceAsStream(res); if (in == null) { - System.err.println("WARNING: no SQL file for driver '" - + driver + "' found."); + logger.warn("No SQL file for driver '" + driver + "' found."); res = "/sql/" + DBConnection.DEFAULT_DRIVER.replace('.', '-').toLowerCase() + ".properties"; if ((in = SQL.class.getResourceAsStream(res)) == null) { - System.err.println("ERROR: no SQL file found"); + logger.error("No SQL file found"); } } properties.load(in); } catch (IOException ioe) { - ioe.printStackTrace(System.err); + logger.error(ioe.getLocalizedMessage(), ioe); } finally { if (in != null) {