Skip to content

Commit

Permalink
First pass at Symmetric Logger with internationalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanes committed Aug 15, 2009
1 parent 4224153 commit 7eec56e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 10 additions & 13 deletions symmetric/src/main/java/org/jumpmind/symmetric/db/SqlScript.java
Expand Up @@ -30,8 +30,8 @@

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.common.logging.Log;
import org.jumpmind.symmetric.common.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcTemplate;
Expand Down Expand Up @@ -85,7 +85,7 @@ private void closeQuietly(Statement stmt) {
try {
stmt.close();
} catch (SQLException e) {
logger.error(e, e);
logger.error(e);
}
}
}
Expand All @@ -106,7 +106,7 @@ public Object doInConnection(Connection connection) throws SQLException, DataAcc
Statement st = null;
String fileName = script.getFile();
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
logger.info("Running " + fileName);
logger.info("ScriptRunning", fileName);
int lineCount = 0;

try {
Expand All @@ -124,9 +124,7 @@ public Object doInConnection(Connection connection) throws SQLException, DataAcc
if (checkStatementEnds(line)) {
sql.append(" ");
sql.append(line.substring(0, line.lastIndexOf(delimiter)));
if (logger.isDebugEnabled()) {
logger.debug("query->" + sql);
}
logger.debug("Sql", sql);
try {
st.execute(replaceTokens(sql.toString()));
count++;
Expand All @@ -135,11 +133,11 @@ public Object doInConnection(Connection connection) throws SQLException, DataAcc
}
} catch (SQLException e) {
if (failOnError) {
logger.error(sql.toString() + " failed to execute.", e);
logger.error("SqlError", sql.toString(), e);
throw e;
} else {
if (e.getErrorCode() != 942 && e.getErrorCode() != 2289) {
logger.warn(e.getMessage() + ": " + sql.toString());
logger.warn("Sql", e.getMessage() + ": " + sql.toString());
} else if (sql.toString().toLowerCase().startsWith("drop")) {
notFoundCount++;
}
Expand All @@ -155,13 +153,12 @@ public Object doInConnection(Connection connection) throws SQLException, DataAcc

connection.commit();

logger.info("Ran " + count + " sql statements in " + fileName);
logger.info("ScriptCompleted", count, fileName);
if (notFoundCount > 0) {
logger.info("Could not drop a total of " + notFoundCount
+ " database object because they were not found");
logger.info("ScriptDropError", notFoundCount);
}
} catch (Exception e) {
logger.info("Error on line " + lineCount + " of " + fileName);
logger.info("ScriptError", lineCount, fileName);
throw new RuntimeException(e);
} finally {
closeQuietly(st);
Expand Down
5 changes: 5 additions & 0 deletions symmetric/src/main/resources/logMessages_en_US.properties
Expand Up @@ -11,6 +11,11 @@ FunctionInstalled=Just installed %s
PostgreSqlCustomVariableMissing=Please add "custom_variable_classes = 'symmetric'" to your postgresql.conf file
PostTriggerCreateFailed=Failed to create post trigger: %s
Sql=SQL: %s
ScriptRunning=Running %s
ScriptCompleted=Ran %d SQL statements in %s
ScriptError=Error on line %d of %s
ScriptDropError=Could not drop a total of %d database objects because they were not found.
SqlError=%s failed to execute.
TableDropped=Just dropped table %s_CONFIG
TablesCreating=About to create SymmetricDS tables
TablesCreatingSkipped=No need to create SymmetricDS tables. They already exist.
Expand Down

0 comments on commit 7eec56e

Please sign in to comment.