Skip to content

Commit

Permalink
add logging notice for startup
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 15, 2018
1 parent 4b11e72 commit 93186d8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
Expand Up @@ -77,6 +77,7 @@
import org.jumpmind.symmetric.statistic.StatisticManager;
import org.jumpmind.symmetric.util.LogSummaryAppenderUtils;
import org.jumpmind.symmetric.util.SnapshotUtil;
import org.jumpmind.symmetric.util.SymmetricUtils;
import org.jumpmind.symmetric.util.TypedPropertiesFactory;
import org.jumpmind.util.AppUtils;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
Expand Down Expand Up @@ -200,7 +201,10 @@ protected SecurityServiceType getSecurityServiceType() {
protected void init() {
try {
LogSummaryAppenderUtils.registerLogSummaryAppender();


if (getSecurityServiceType().equals(SecurityServiceType.CLIENT)) {
SymmetricUtils.logNotices();
}
super.init();

this.monitorService = new MonitorService(parameterService, symmetricDialect, nodeService, extensionService,
Expand Down
Expand Up @@ -24,30 +24,41 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.Version;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.util.AppUtils;
import org.jumpmind.util.CollectionUtils;
import org.jumpmind.util.FormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final public class SymmetricUtils {

protected static final Logger log = LoggerFactory.getLogger(SymmetricUtils.class);

protected static boolean isJava7 = true;

protected static Method copyMethod;

protected static Method fileMethod;

protected static Object optionArray;

protected static boolean isNoticeLogged;

private SymmetricUtils() {
}
Expand Down Expand Up @@ -125,6 +136,59 @@ public static final void replaceSystemAndEnvironmentVariables(Properties propert
properties.put(object, value);
}
}
}
}

public static void logNotices() {
synchronized (SymmetricUtils.class) {
if (isNoticeLogged) {
return;
}
isNoticeLogged = true;
}

String notices = null;
try {
notices = String.format("%n%s%n", IOUtils.toString(Thread.currentThread().getContextClassLoader().getResource("symmetricds.asciiart")));
} catch (Exception ex) {
notices = String.format("SymmetricDS Start%n");
}

String buildTime = Long.toString(Version.getBuildTime());
String year = null;
if (buildTime.length() >= 4) {
year = buildTime.substring(0, 4);
} else {
year = new SimpleDateFormat("yyyy").format(new Date());
}

int pad = 65;
notices += String.format(
"+" + StringUtils.repeat("-", pad) + "+%n" +
"|" + StringUtils.rightPad(" Copyright (C) 2007-" + year + " JumpMind, Inc.", pad) + "|%n" +
"|" + StringUtils.repeat(" ", pad) + "|%n");

InputStream in = null;
try {
in = AppUtils.class.getResourceAsStream("/symmetric-console-default.properties");
if (in != null) {
in.close();
}
} catch (Exception e) {
}

if (in != null) {
notices += String.format(
"|" + StringUtils.rightPad(" Licensed under one or more agreements from JumpMind, Inc.", pad) + "|%n" +
"|" + StringUtils.rightPad(" See docs/license.html", pad) + "|%n");
} else {
notices += String.format(
"|" + StringUtils.rightPad(" Licensed under the GNU General Public License version 3.", pad) + "|%n" +
"|" + StringUtils.rightPad(" This software comes with ABSOLUTELY NO WARRANTY.", pad) + "|%n" +
"|" + StringUtils.rightPad(" See http://www.gnu.org/licenses/gpl.html", pad) + "|%n");
}

notices += "+" + StringUtils.repeat("-", pad) + "+";
log.info(notices);
}

}
Expand Up @@ -33,7 +33,6 @@
import javax.websocket.server.ServerContainer;
import javax.websocket.server.ServerEndpointConfig;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.http.HttpVersion;
Expand Down Expand Up @@ -63,6 +62,7 @@
import org.jumpmind.symmetric.common.ServerConstants;
import org.jumpmind.symmetric.common.SystemConstants;
import org.jumpmind.symmetric.transport.TransportManagerFactory;
import org.jumpmind.symmetric.util.SymmetricUtils;
import org.jumpmind.symmetric.web.HttpMethodFilter;
import org.jumpmind.symmetric.web.ServletUtils;
import org.jumpmind.symmetric.web.SymmetricEngineHolder;
Expand Down Expand Up @@ -243,7 +243,7 @@ public SymmetricWebServer startMixed(int httpPort, int secureHttpPort, int jmxPo

public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, Mode mode) throws Exception {

printAsciiArt();
SymmetricUtils.logNotices();

TransportManagerFactory.initHttps(httpSslVerifiedServerNames, allowSelfSignedCerts);

Expand Down Expand Up @@ -308,14 +308,6 @@ public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, M
return this;
}

protected void printAsciiArt() {
try {
log.info("SymmetricWebServer START\r\n{}", IOUtils.toString(Thread.currentThread().getContextClassLoader().getResource("symmetricds.asciiart")));
} catch (Exception ex) {
// ignored.
}
}

protected ServletContext getServletContext() {
return webapp != null ? webapp.getServletContext() : null;
}
Expand Down
Expand Up @@ -64,6 +64,7 @@
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.jumpmind.symmetric.util.SymmetricUtils;
import org.jumpmind.util.CustomizableThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -178,6 +179,8 @@ public synchronized void stop() {

public void start() {
try {
SymmetricUtils.logNotices();

if (staticEnginesMode) {
log.info("In static engine mode");
engines = staticEngines;
Expand Down

0 comments on commit 93186d8

Please sign in to comment.