Skip to content

Commit

Permalink
fabric8io#85: Reduce logging noise a bit and add logo at the end with…
Browse files Browse the repository at this point in the history
… links for consoles
  • Loading branch information
davsclaus committed Nov 25, 2014
1 parent cd9e924 commit 313c3bc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
5 changes: 3 additions & 2 deletions images/fabric8/java/src/main/distro/bin/launcher.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ set APP_CONSOLE_OUT=%APP_BASE%\logs\out.log
set APP_CONSOLE_ERR=%APP_BASE%\logs\err.log

rem Add the files in the maven dir using wildcard style
rem (this is needed on windows as the command line can get too large otherwise)
if "%CLASSPATH%" == "" (
set CLASSPATH=%APP_BASE%\maven\*;classes
set CLASSPATH=%APP_BASE%\maven\*;%APP_BASE%\classes
) else (
set CLASSPATH=%CLASSPATH%;%APP_BASE%\maven\*;classes
set CLASSPATH=%CLASSPATH%;%APP_BASE%\maven\*;%APP_BASE%\classes
)

rem get current dir name only (which is a bit odd way to do in windows bat)
Expand Down
50 changes: 43 additions & 7 deletions jube/src/main/java/io/fabric8/jube/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;

import io.fabric8.jube.apimaster.ApiMasterService;
import io.fabric8.jube.util.JubeVersionUtils;
import io.fabric8.kubernetes.api.KubernetesClient;
import io.fabric8.kubernetes.api.KubernetesFactory;
import io.fabric8.kubernetes.api.KubernetesManager;
Expand All @@ -49,6 +50,16 @@ public final class Main {
private static final String JUBE_VERSION = System.getenv("JUBE_VERSION") != null ? System.getenv("JUBE_VERSION") : "LATEST";
private static final String FABRIC8_VERSION = System.getenv("FABRIC8_VERSION") != null ? System.getenv("FABRIC8E_VERSION") : "LATEST";

private static final String JUL_LOGGING_FORMAT = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n";

private static final String LOGO =
"\t________ ______\n" +
"\t______(_)____ _____ /_ _____\n" +
"\t_____ / _ / / /__ __ \\_ _ \\\n" +
"\t____ / / /_/ / _ /_/ // __/\n" +
"\t___ / \\__,_/ /_.___/ \\___/\n" +
"\t/___/\n";

private Main() {
// run as main class
}
Expand All @@ -57,7 +68,7 @@ public static void main(final String[] args) throws Exception {
try {
System.setProperty("hawtio.authenticationEnabled", "false");
System.setProperty("org.eclipse.jetty.util.log.class", Slf4jLog.class.getName());

System.setProperty("java.util.logging.SimpleFormatter.format", JUL_LOGGING_FORMAT);
String port = Systems.getEnvVarOrSystemProperty("HTTP_PORT", "HTTP_PORT", "8585");
Integer portNumber = Integer.parseInt(port);

Expand All @@ -71,13 +82,12 @@ public static void main(final String[] args) throws Exception {

// lets find wars on the classpath
Set<String> foundURLs = new HashSet<>();
findWarsOnClassPath(server, handlers, Thread.currentThread().getContextClassLoader(), foundURLs, portNumber);
String hawtio1 = findWarsOnClassPath(server, handlers, Thread.currentThread().getContextClassLoader(), foundURLs, portNumber);

ClassLoader classLoader = Main.class.getClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);


findWarsOnClassPath(server, handlers, classLoader, foundURLs, portNumber);
String hawtio2 = findWarsOnClassPath(server, handlers, classLoader, foundURLs, portNumber);

// In case you want to run in an IDE, and it does not setup the classpath right.. lets
// find the .war files in the maven dir. Assumes you set the working dir to the target/jube dir.
Expand Down Expand Up @@ -114,6 +124,22 @@ public static void main(final String[] args) throws Exception {
handlers.addHandler(context);

server.start();

System.out.println("\n\n");
System.out.println(LOGO);

String version = JubeVersionUtils.getReleaseVersion();
if (version != null) {
System.out.println("\t Version " + version + "\n");
}
if (hawtio1 != null) {
System.out.println("\t Web console: http://" + ApiMasterService.getHostName() + ":" + port + "/" + hawtio1 + "/");
} else if (hawtio2 != null) {
System.out.println("\t Web console: http://" + ApiMasterService.getHostName() + ":" + port + "/" + hawtio2 + "/");
}
System.out.println("\t REST api: http://" + ApiMasterService.getHostName() + ":" + port + "/api/");
System.out.println("\n\n");

server.join();
} catch (Throwable e) {
logException(e);
Expand Down Expand Up @@ -183,7 +209,8 @@ protected static void logException(Throwable e) {
}
}

protected static void findWarsOnClassPath(Server server, HandlerCollection handlers, ClassLoader classLoader, Set<String> foundURLs, Integer port) {
protected static String findWarsOnClassPath(Server server, HandlerCollection handlers, ClassLoader classLoader, Set<String> foundURLs, Integer port) {
String answer = null;
try {
Enumeration<URL> resources = classLoader.getResources("WEB-INF/web.xml");
while (resources.hasMoreElements()) {
Expand All @@ -192,16 +219,22 @@ protected static void findWarsOnClassPath(Server server, HandlerCollection handl
if (text.startsWith("jar:")) {
text = text.substring(4);
}
createWebapp(handlers, foundURLs, port, text);
String path = createWebapp(handlers, foundURLs, port, text);
if (path != null) {
answer = path;
}
}
} catch (Exception e) {
System.out.println("Failed to find web.xml on classpath: " + e);
e.printStackTrace();
}

return answer;
}

private static void createWebapp(HandlerCollection handlers, Set<String> foundURLs, Integer port, String war) {
private static String createWebapp(HandlerCollection handlers, Set<String> foundURLs, Integer port, String war) {
String answer = null;

if (foundURLs.add(war)) {
String contextPath = createContextPath(war);
String filePath = createFilePath(war);
Expand All @@ -211,6 +244,7 @@ private static void createWebapp(HandlerCollection handlers, Set<String> foundUR
System.out.println("hawtio is running on http://" + ApiMasterService.getHostName() + ":" + port + "/" + contextPath + "/");
System.out.println("==================================================");
System.out.println();
answer = contextPath;
} else {
System.out.println("adding web context path: /" + contextPath + " war: " + filePath);
}
Expand All @@ -227,6 +261,8 @@ private static void createWebapp(HandlerCollection handlers, Set<String> foundUR
logException(e);
}
}

return answer;
}

/**
Expand Down
28 changes: 0 additions & 28 deletions jube/src/main/resources/log4j.properties

This file was deleted.

3 changes: 2 additions & 1 deletion jube/src/main/resources/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

.level = INFO
org.eclipse.jetty.level = INFO
org.eclipse.jetty.server.Server.level = FINE
org.eclipse.jetty.server.Server.level = INFO
org.apache.zookeeper.server.level = WARN

0 comments on commit 313c3bc

Please sign in to comment.