Skip to content

Commit

Permalink
SYMMETRICDS-290 - added new logging options for standalone deployment…
Browse files Browse the repository at this point in the history
…. also cleaned up a few logging issues to make logging less verbose for unregistered nodes.
  • Loading branch information
chenson42 committed Sep 14, 2010
1 parent abb8c99 commit 2f56fbb
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 29 deletions.
17 changes: 17 additions & 0 deletions symmetric/symmetric-ds/src/main/deploy/conf/log4j-blank.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>

<root>
<priority value="INFO" />
<appender-ref ref="CONSOLE" />
</root>

</log4j:configuration>
53 changes: 53 additions & 0 deletions symmetric/symmetric-ds/src/main/deploy/conf/log4j-debug.xml
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="ROLLING" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="../logs/symmetric.log" />
<param name="MaxFileSize" value="10000KB" />
<param name="MaxBackupIndex" value="3" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{2}] [%t] %m%n" />
</layout>
</appender>

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%c{1} - %m%n" />
</layout>
</appender>

<category name="org">
<priority value="WARN" />
</category>

<category name="org.springframework">
<priority value="ERROR" />
</category>

<category name="org.jumpmind">
<priority value="INFO" />
</category>

<category name="org.jumpmind.symmetric">
<priority value="DEBUG" />
</category>

<category name="org.jumpmind.symmetric.ddl.platform.derby">
<priority value="ERROR" />
</category>

<category name="org.jumpmind.symmetric.job.HeartbeatJob">
<priority value="INFO" />
</category>

<!-- Change the "CONSOLE" to "ROLLING" to log to a file instead -->
<root>
<priority value="INFO" />
<appender-ref ref="ROLLING" />
<appender-ref ref="CONSOLE" />
</root>

</log4j:configuration>
5 changes: 3 additions & 2 deletions symmetric/symmetric-ds/src/main/deploy/conf/log4j.xml
Expand Up @@ -9,13 +9,13 @@
<param name="MaxBackupIndex" value="3" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{2}] [%t] %m%n" />
<param name="ConversionPattern" value="%d %-5p [%c{1}] [%t] %m%n" />
</layout>
</appender>

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{2}] [%t] %m%n" />
<param name="ConversionPattern" value="%c{1} - %m%n" />
</layout>
</appender>

Expand Down Expand Up @@ -71,6 +71,7 @@
<root>
<priority value="INFO" />
<appender-ref ref="ROLLING" />
<appender-ref ref="CONSOLE" />
</root>

</log4j:configuration>
7 changes: 4 additions & 3 deletions symmetric/symmetric-ds/src/main/deploy/conf/sym_service.conf
Expand Up @@ -48,9 +48,10 @@ wrapper.java.maxmemory=256

# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=org.jumpmind.symmetric.SymmetricLauncher
wrapper.app.parameter.2=--server
wrapper.app.parameter.3=--port
wrapper.app.parameter.4=31415
wrapper.app.parameter.2=--noconsole
wrapper.app.parameter.3=--server
wrapper.app.parameter.4=--port
wrapper.app.parameter.5=31415

#********************************************************************
# Wrapper Logging Properties
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.sql.Connection;

Expand All @@ -40,7 +41,12 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.xml.DOMConfigurator;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.Message;
import org.jumpmind.symmetric.common.SecurityConstants;
Expand Down Expand Up @@ -120,6 +126,12 @@ public class SymmetricLauncher {
private static final String OPTION_ENCRYPT_TEXT = "encrypt";

private static final String OPTION_VERBOSE_CONSOLE = "verbose";

private static final String OPTION_DEBUG = "debug";

private static final String OPTION_NOCONSOLE = "noconsole";

private static final String OPTION_NOLOGFILE = "nologfile";

private static final String MESSAGE_BUNDLE = "Launcher.Option.";

Expand All @@ -143,27 +155,57 @@ public static void main(String... args) throws Exception {
boolean noNio = false;
boolean noDirectBuffer = false;

File log4jFile = getLog4JFile();
if (line.hasOption(OPTION_DEBUG)) {
log4jFile = getLog4JFileDebugEnabled();
}

if (log4jFile.exists()) {
DOMConfigurator.configure(log4jFile.getAbsolutePath());
}

if (line.hasOption(OPTION_VERBOSE_CONSOLE)) {
System.setProperty("org.apache.commons.logging.Log", SimpleLog.class.getName());
System.setProperty("org.apache.commons.logging.simplelog.showlogname", "false");

System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "info");
System.setProperty("org.apache.commons.logging.simplelog.log.org", "error");
System.setProperty("org.apache.commons.logging.simplelog.log.org.jumpmind", "info");
System.setProperty("org.apache.commons.logging.simplelog.log.org.jumpmind.symmetric.config.PropertiesFactoryBean", "error");

} else {
System.out.println(Message.get("LauncherLogLocation"));

// Log options to the log file only. No need to log them to the console
if (line.getOptions() != null) {
for (Option option : line.getOptions()) {
LogFactory.getLog(SymmetricLauncher.class).info("Option", option.getLongOpt(),
ArrayUtils.toString(option.getValues()));
Appender consoleAppender = Logger.getRootLogger().getAppender("CONSOLE");
if (consoleAppender != null) {
Layout layout = consoleAppender.getLayout();
if (layout instanceof PatternLayout) {
((PatternLayout)layout).setConversionPattern("%d %-5p [%c{2}] [%t] %m%n");
}
}
}

if (line.hasOption(OPTION_NOCONSOLE)) {
Logger.getRootLogger().removeAppender("CONSOLE");
}

if (line.hasOption(OPTION_NOLOGFILE)) {
Logger.getRootLogger().removeAppender("ROLLING");
} else {
if (line.hasOption(OPTION_PROPERTIES_FILE)) {
File file = new File(line.getOptionValue(OPTION_PROPERTIES_FILE));
String name = file.getName();
int index = name.lastIndexOf(".");
if (index > 0) {
name = name.substring(0, index);
}
Appender appender = Logger.getRootLogger().getAppender("ROLLING");
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender)appender;
fileAppender.setFile(fileAppender.getFile().replace("symmetric.log", name + ".log"));
fileAppender.activateOptions();
System.out.println(Message.get("LauncherLogLocation", fileAppender.getFile()));
}
}
}

// Log options to the log file only. No need to log them to the console
if (line.getOptions() != null) {
for (Option option : line.getOptions()) {
LogFactory.getLog(SymmetricLauncher.class).info("Option", option.getLongOpt(),
ArrayUtils.toString(option.getValues()));
}
}

if (line.hasOption(OPTION_PORT_SERVER)) {
port = new Integer(line.getOptionValue(OPTION_PORT_SERVER));
}
Expand Down Expand Up @@ -328,6 +370,16 @@ public static void main(String... args) throws Exception {
System.exit(-1);
}
}

private static File getLog4JFile() throws MalformedURLException {
URL url = new URL(System.getProperty("log4j.configuration", "file:../conf/log4j-blank.xml"));
return new File(new File(url.getFile()).getParent(), "log4j.xml");
}

private static File getLog4JFileDebugEnabled() throws MalformedURLException {
File original = getLog4JFile();
return new File(original.getParent(), "log4j-debug.xml");
}

private static void printHelp(Options options) {
new HelpFormatter().printHelp("sym", options);
Expand Down Expand Up @@ -372,6 +424,9 @@ private static Options buildOptions() {
addOption(options, "o", OPTION_TRIGGER_GEN_ALWAYS, false);
addOption(options, "e", OPTION_ENCRYPT_TEXT, true);
addOption(options, "v", OPTION_VERBOSE_CONSOLE, false);
addOption(options, OPTION_DEBUG, OPTION_DEBUG, false);
addOption(options, OPTION_NOCONSOLE, OPTION_NOCONSOLE, false);
addOption(options, OPTION_NOLOGFILE, OPTION_NOLOGFILE, false);

addOption(options, "x", OPTION_EXPORT_SCHEMA, true);

Expand Down
Expand Up @@ -69,6 +69,8 @@ abstract public class AbstractJob implements Runnable, BeanNameAware {
private long timeBetweenRunsInMs;

private String cronExpression;

private boolean hasNotRegisteredMessageBeenLogged = false;

public String getName() {
return beanName;
Expand Down Expand Up @@ -98,9 +100,13 @@ public boolean invoke(boolean force) {
if (!requiresRegistration
|| (requiresRegistration && registrationService
.isRegisteredWithServer())) {
hasNotRegisteredMessageBeenLogged = false;
doJob();
} else {
log.warn("SymmetricEngineNotRegistered");
if (!hasNotRegisteredMessageBeenLogged) {
log.warn("SymmetricEngineNotRegistered", getName());
hasNotRegisteredMessageBeenLogged = true;
}
}
} finally {
lastFinishTime = new Date();
Expand Down
Expand Up @@ -660,7 +660,7 @@ public void heartbeat(boolean force) {
updateLastHeartbeatTime(listeners);

} else {
log.info("HeartbeatUpdatingFailure");
log.debug("HeartbeatUpdatingFailureNodeNotConfigured");
}
}
}
Expand Down
Expand Up @@ -118,7 +118,7 @@ FindNodeSecurityNodeNull=A 'null' node id was passed into findNodeSecurity.
FirebirdSymUdfMissing=Please install the sym_udf.so/dll to your {firebird_home}/UDF folder
FirebirdSymEscapeMissing=Function SYM_ESCAPE is not installed
FunctionInstalled=Just installed %s
HeartbeatUpdatingFailure=Did not run the heartbeat process because the cluster service has it locked.
HeartbeatUpdatingFailureNodeNotConfigured=Did not run the heartbeat process because the node has not been configured
JMXAdaptorUnregisterFailed=Could not unregister the JMX HTTP Adaptor
JMXBeansRegisterError=Unable to register JMX Beans with the default MBeanServer: %s
JMXConsoleStarting=Starting JMX HTTP console on port %d
Expand All @@ -129,7 +129,7 @@ JobFailedToSchedule=Failed to schedule this job, %s
JobFailedToFind=Failed to find the job name %s
JobRescheduling=Rescheduling %s with %s ms delay
JobStarting=Starting %s
LauncherLogLocation=Check in the logs directory for program output or run with the -v option to log output to the console
LauncherLogLocation=Log output will be written to %s
LauncherMissingArgument=Check the argument you passed in. --%s takes an argument of {groupId},{externalId}
LauncherMissingFilenameTriggerSQL=Please provide a file name to write the trigger SQL to
LoaderTokenUnexpected=Unexpected token '%s' on line %d of batch %d
Expand Down Expand Up @@ -232,7 +232,7 @@ SymmetricDSUpgradeFailed=The upgrade failed. The system may be unstable. Pleas
SymmetricDSUpgradeNeeded=Upgrade of node is necessary. Please set the auto.upgrade property to true for an automated upgrade.
SymmetricDSManualUpgradeNeeded=A manual upgrade of the node is required. Can not automatically upgrade from version %s to version %s.
SymmetricEngineMissing=Could not find a reference to the SymmetricEngine from %s
SymmetricEngineNotRegistered=Did not run job because the engine is not registered.
SymmetricEngineNotRegistered=Did not run the %s job because the engine is not registered.
SymmetricEngineNotStarted=The engine is not currently started.
SyncDisabled=Synchronization is disabled on the server node.
TableDropped=Just dropped table %s_CONFIG
Expand Down Expand Up @@ -307,10 +307,13 @@ Launcher.Option.skip-db-validate=Don't test to see if the database connection is
Launcher.Option.generate-triggers=Run the sync triggers process and write the output the specified file. If triggers should not be applied automatically then set the auto.sync.triggers property to false
Launcher.Option.generate-triggers-always=Run the sync triggers process even if the triggers already exist.
Launcher.Option.encrypt=Encrypts the given text for use with db.user and db.password properties
Launcher.Option.verbose=Log output to the console instead of the log file
Launcher.Option.verbose=Extra information will be sent to the console
Launcher.Option.debug=Debug information will be enabled in the logger
Launcher.Option.export-schema=Export the entire database schema for the configured database connection to XML. Takes an argument of the file name.
Launcher.Option.no-nio=Do not use Non-blocking IO for the HTTP connector
Launcher.Option.no-directbuffer=Do not use direct buffers for the NIO HTTP connector
Launcher.Option.noconsole=No output will be sent to the console
Launcher.Option.nologfile=The log file will not be created on the file system
XmlPublisherTableNotFound='%s' not in list to publish
ValidationSetRegistrationUrl=Please set the property %s so this node may pull registration or manually insert configuration into the configuration tables.
ValidationComparePropertiesToDatabase=The configured state does not match recorded database state. The recorded external id is %s while the configured external id is %s. The recorded node group id is %s while the configured node group id is %s.
Expand Down
Expand Up @@ -12,7 +12,7 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.jumpmind.symmetric.SymmetricLauncher"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-v -p root.properties --auto-create"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-p root.properties --auto-create"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="symmetric-ds"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:symmetric-ds/src/main/deploy/samples}"/>
</launchConfiguration>

0 comments on commit 2f56fbb

Please sign in to comment.