args.add("-Dlauncher.appbase=" + getAppbase().toString());
args.add("-Dlauncher.appdir=" + getAppDir());
args.add("-Dlauncher.version=" + Build.version());
- if (System.getProperty("installer.appdir") != null) {
- args.add("-Dinstaller.appdir=" + System.getProperty("installer.appdir"));
- }
+ addSystemPropertyIfNotNull(args, "installer.appdir");
// add the marker indicating the app is running in getdown
args.add("-D" + Properties.GETDOWN + "=true");
args.add("-Dsys.install4jVersion=" + Application.i4jVersion);
- if (System.getProperty("installer.template_version") != null) {
- args.add("-Dinstaller.template_version=" + System.getProperty("installer.template_version"));
- }
- if (System.getProperty("installer.logfile") != null) {
- args.add("-Dinstaller.logfile=" + System.getProperty("installer.logfile"));
- }
- if (System.getProperty("installer.extrainfo") != null) {
- args.add("-Dinstaller.extrainfo=" + System.getProperty("installer.extrainfo"));
- }
+ addSystemPropertyIfNotNull(args, "installer.template_version");
+ addSystemPropertyIfNotNull(args, "installer.logfile");
+ addSystemPropertyIfNotNull(args, "installer.logfile_append");
+ addSystemPropertyIfNotNull(args, "installer.extrainfo");
// backward compatibility (old getdown-launcher.jar)
args.add("-Dgetdownappdir=" + getAppDir());
if (! StringUtil.isBlank(_jalviewUri)) {
_appargs.add(0, _jalviewUri);
}
- /* don't convert jalviewX:// URIs to https:// URLs as Jalview can now do that
- if (_appargs.size() > 0) {
- String jalviewUri = _appargs.get(0);
- log.info("Trying to parse uri '"+jalviewUri+"'");
- if (HttpUtils.isJalviewSchemeUri(jalviewUri)) {
- String jalviewUrl = HttpUtils.equivalentJalviewUrl(jalviewUri);
- log.info("Turned url '"+jalviewUri+"' into '"+jalviewUrl+"'");
- _appargs.clear();
- _appargs.add(jalviewUrl);
- }
- }
- */
for (String argString: _appargs) {
if (argString.startsWith("-jvmmempc=")) {
String[] envp = createEnvironment();
String[] sargs = args.toArray(new String[args.size()]);
- log.info("Running " + StringUtil.join(sargs, "\n "));
+ log.info("Running \"" + StringUtil.join(sargs, "\" \\\n \"") + "\"");
// don't set the working dir, leave it the same as the working dir of the invocation
//return Runtime.getRuntime().exec(sargs, envp, getAppDir());
}
}
+ private static void addSystemPropertyIfNotNull(List<String> args, String key) {
+ if (args == null || key == null || System.getProperty(key) == null) {
+ return;
+ }
+ StringBuilder sb = new StringBuilder("-D");
+ sb.append(key);
+ sb.append("=");
+ sb.append(System.getProperty(key));
+ args.add(sb.toString());
+ }
+
protected final EnvConfig _envc;
protected File _config;
protected File _backupConfig;
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
- if (!_closed) {
- out.println(line);
- out.flush();
- }
// look for logfile handover
- if (line.equals(LaunchUtils.LOGFILE_HANDOVER)) {
+ if (line.endsWith(LaunchUtils.LOGFILE_HANDOVER)) {
+ out.println("LAUNCHER end of logging");
out.flush();
out.close();
_closed = true;
}
- // check for desktop creation line and end early
+ if (!_closed) {
+ out.println("LAUNCHER pass-through: "+line);
+ out.flush();
+ }
+ // check for desktop creation line and close splashscreen early
if (!_disposed && line.endsWith(": CREATED DESKTOP")) {
// pump the percent up to 100%
if (_latestInstance != null) {
*/
public static Getdown start (String[] argv) throws Exception {
jalview.util.ErrorLog.setHasConsole(false);
- jalview.util.ErrorLog.setPrefix("LAUNCHER - ");
+ jalview.util.ErrorLog.setPrefix("LAUNCHER: ");
+ jalview.util.ErrorLog.outPrintln("start of logging");
List<EnvConfig.Note> notes = new ArrayList<>();
boolean append = false;
EnvConfig envc = EnvConfig.create(argv, notes, GetdownApp.class);
logFileName = System.getProperty("user.home") + File.separator + logFileName.substring(2);
}
logFile = new File(logFileName);
- append = true;
+ append = Boolean.parseBoolean(System.getProperty("installer.logfile_append"));
} else {
logFile = new File(envc.appDir, "launcher.log");
}
try {
PrintStream logOut = new PrintStream(
new BufferedOutputStream(new FileOutputStream(logFile, append)), true);
+
System.setOut(logOut);
System.setErr(logOut);
- log.info(Note.info("LAUNCHER starting to log"));
- log.info(Note.info("Launcher logging to '" + logFile.getAbsolutePath() + "'"));
} catch (IOException ioe) {
log.warning("Unable to redirect output to '" + logFile + "': " + ioe);
}
}
// record a few things for posterity
- log.info("------------------ VM Info ------------------");
+ log.info("------------- Launcher VM Info --------------");
log.info("-- OS Name: " + System.getProperty("os.name"));
log.info("-- OS Arch: " + System.getProperty("os.arch"));
log.info("-- OS Vers: " + System.getProperty("os.version"));
*/
package jalview.bin;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.PrintStream;
+import java.util.Locale;
import jalview.log.JLogger;
import jalview.log.JLoggerI.LogLevel;
import jalview.log.JLoggerLog4j;
import jalview.util.ChannelProperties;
-import jalview.util.Log4j;
-import jalview.util.Platform;
+import jalview.util.LaunchUtils;
public class Console
{
public static JLoggerLog4j log;
+ private static PrintStream out = System.out;
+
+ private static PrintStream err = System.err;
+
+ private static File logfile = null;
+
+ public static PrintStream getOut()
+ {
+ return out;
+ }
+
+ public static PrintStream getErr()
+ {
+ return err;
+ }
+
+ public static void setOut(PrintStream p)
+ {
+ out = p;
+ }
+
+ public static void setErr(PrintStream p)
+ {
+ err = p;
+ }
+
+ public static boolean setLogFile(String filename, boolean append)
+ {
+ boolean usingLogfile = false;
+ if (filename != null)
+ {
+ if (filename.startsWith("~/"))
+ {
+ filename = System.getProperty("user.home") + File.separator
+ + filename.substring(2);
+ }
+ logfile = new File(filename);
+
+ try
+ {
+ PrintStream logFilePrintStream = new PrintStream(
+ new BufferedOutputStream(
+ new FileOutputStream(logfile, append)),
+ true);
+
+ Console.setOut(logFilePrintStream);
+ Console.setErr(logFilePrintStream);
+
+ Console.info(LaunchUtils.LOGFILE_HANDOVER);
+
+ Console.info(ChannelProperties.getProperty("app_name")
+ .toUpperCase(Locale.ROOT) + " start of logging");
+ Console.debug(ChannelProperties.getProperty("app_name")
+ + " logging to " + filename);
+
+ usingLogfile = true;
+ } catch (FileNotFoundException e)
+ {
+ Console.errPrintln("Error opening logfile: " + e.getMessage());
+ }
+ }
+ return usingLogfile;
+ }
+
public static void debug(String message, Throwable t)
{
if (Console.initLogger())
outPrintln(message);
Console.printStackTrace(t);
}
-
}
public static void info(String message)
logLevel = getCachedLogLevel();
}
- if (!Platform.isJS())
- {
- if (!Jalview.quiet())
- {
- jalview.bin.Console.errPrintln(
- "Setting initial log level to " + logLevel.name());
- }
- Log4j.init(logLevel);
- }
+ JLoggerLog4j.setLogfile(logfile);
+
// log output
// is laxis used? Does getLogger do anything without a Logger object?
// Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
Console.debug("Invalid log level '" + logLevelString + "'");
return;
}
+ setLogLevel(l);
+ }
+
+ public static void setLogLevel(LogLevel l)
+ {
if (l != null)
{
log.setLevel(l);
- if (!Platform.isJS())
- {
- Log4j.init(l);
- }
JLoggerLog4j.getLogger("org.apache.axis", l);
}
}
&& Jalview.getInstance().getBootstrapArgs() != null
&& Jalview.getInstance().getBootstrapArgs().outputToStdout())
{
- return System.err;
+ return err;
}
else
{
- return System.out;
+ return out;
}
}
public static void errPrint(Object message)
{
- System.err.print(message);
+ err.print(message);
}
public static void errPrintln(Object message)
{
- System.err.println(message);
+ err.println(message);
}
public static void debugPrintStackTrace(Throwable t)
public static void printStackTrace(Throwable t)
{
// send message to stderr if output to stdout is expected
- t.printStackTrace(System.err);
+ t.printStackTrace(err);
}
public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";
package jalview.bin;
import java.awt.Color;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
// get args needed before proper ArgParser
bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
+ boolean usingLogfile = false;
if (!Platform.isJS())
{
- boolean usingLogfile = false;
// are we using a logfile?
- String logFileName = System.getProperty("installer.logfile");
- if (logFileName != null)
- {
- try
- {
- if (logFileName.startsWith("~/"))
- {
- logFileName = System.getProperty("user.home") + File.separator
- + logFileName.substring(2);
- }
- File logFile = new File(logFileName);
-
- PrintStream logFilePrintStream = new PrintStream(
- new BufferedOutputStream(
- new FileOutputStream(logFile, true)),
- true);
-
- Console.info(LaunchUtils.LOGFILE_HANDOVER);
- System.setOut(logFilePrintStream);
- System.setErr(logFilePrintStream);
- Console.info(ChannelProperties.getProperty("app_name")
- .toUpperCase(Locale.ROOT) + " starting to log");
- Console.info(ChannelProperties.getProperty("app_name")
- + " logging to " + logFileName);
-
- usingLogfile = true;
- } catch (FileNotFoundException e)
- {
- Console.errPrintln("Error opening logfile: " + e.getMessage());
- }
- }
+ String logfilename = System.getProperty("installer.logfile");
+ boolean append = Boolean
+ .parseBoolean(System.getProperty("installer.logfile_append"));
+
+ usingLogfile = Console.setLogFile(logfilename, append);
// are we being --quiet ? (doesn't matter if using a logfile)
if (!usingLogfile && bootstrapArgs.contains(Arg.QUIET))
QUIET = true;
OutputStream devNull = new OutputStream()
{
-
@Override
public void write(int b)
{
}.start();
}
- if (!quiet() || !bootstrapArgs.outputToStdout()
+ if ((usingLogfile || !quiet()) || !bootstrapArgs.outputToStdout()
|| bootstrapArgs.contains(Arg.VERSION))
{
- Console.outPrintln(
- "Java version: " + System.getProperty("java.version"));
- Console.outPrintln("Java home: " + System.getProperty("java.home"));
- Console.outPrintln("Java arch: " + System.getProperty("os.arch") + " "
- + System.getProperty("os.name") + " "
- + System.getProperty("os.version"));
-
- String val = System.getProperty("sys.install4jVersion");
- if (val != null)
- {
- Console.outPrintln("Installer version: " + val);
- }
- val = System.getProperty("installer.template_version");
- if (val != null)
- {
- Console.outPrintln("Installer template version: " + val);
- }
- val = System.getProperty("installer.appdir");
- if (val != null)
- {
- Console.outPrintln("Installer appdir: " + val);
- }
- val = System.getProperty("installer.extrainfo");
- if (val != null)
- {
- Console.outPrintln("Installer extrainfo: " + val);
- }
- val = System.getProperty("launcher.version");
- if (val != null)
- {
- Console.outPrintln("Launcher version: " + val);
- }
- val = appdirString;
- if (val != null)
+ if (usingLogfile)
{
- Console.outPrintln("Launcher appdir: " + val);
+ Console.outPrintln("-------");
}
- val = System.getProperty("launcher.appbase");
- if (val != null)
+ Console.outPrint(Cache.getVersionDetailsForConsole());
+ if (usingLogfile)
{
- Console.outPrintln("Launcher appbase: " + val);
+ Console.outPrintln("-------");
}
}
}
System.setProperty("http.agent", UserAgent.getUserAgent());
+ // Initialise the logger
try
{
Console.initLogger();
return registry.get(name);
}
+ @Override
public LogLevel getLevel()
{
return this.level;
}
+ @Override
public void setLevel(LogLevel level)
{
this.level = level;
}
}
+ @Override
public void trace(String message)
{
trace(message, null);
}
+ @Override
public void trace(String message, Throwable t)
{
println(LogLevel.TRACE, message, t);
}
+ @Override
public void debug(String message)
{
debug(message, null);
}
+ @Override
public void debug(String message, Throwable t)
{
println(LogLevel.DEBUG, message, t);
}
+ @Override
public void info(String message)
{
info(message, null);
}
+ @Override
public void info(String message, Throwable t)
{
println(LogLevel.INFO, message, t);
}
+ @Override
public void warn(String message)
{
warn(message, null);
}
+ @Override
public void warn(String message, Throwable t)
{
println(LogLevel.WARN, message, t);
}
+ @Override
public void error(String message)
{
error(message, null);
}
+ @Override
public void error(String message, Throwable t)
{
println(LogLevel.ERROR, message, t);
}
+ @Override
public void fatal(String message)
{
fatal(message, null);
}
+ @Override
public void fatal(String message, Throwable t)
{
println(LogLevel.FATAL, message, t);
}
+ @Override
public boolean isDebugEnabled()
{
return level.compareTo(LogLevel.DEBUG) <= 0;
}
+ @Override
public boolean isTraceEnabled()
{
return level.compareTo(LogLevel.TRACE) <= 0;
*/
package jalview.log;
+import java.io.File;
+
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Appender;
+import jalview.bin.Jalview;
import jalview.util.Log4j;
import jalview.util.Platform;
{
private Logger logger = null;
+ private static File logfile = null;
+
public static JLoggerLog4j getLogger(Class c)
{
- return getLogger(c);
+ return getLogger(c.getCanonicalName());
}
public static JLoggerLog4j getLogger(Class c, LogLevel loglevel)
return getLogger(name, LogLevel.INFO);
}
+ // This must be called before Log4j.init(), so before JLoggerLog4j.getLogger()
+ public static void setLogfile(File f)
+ {
+ logfile = f;
+ }
+
public static JLoggerLog4j getLogger(String name, LogLevel loglevel)
{
+ if (!Platform.isJS())
+ {
+ if (!Jalview.quiet())
+ {
+ jalview.bin.Console
+ .errPrintln("Setting log level to " + loglevel.name());
+ }
+ Log4j.init(loglevel, logfile);
+ }
+
return registryContainsKey(name) ? (JLoggerLog4j) registryGet(name)
: new JLoggerLog4j(name, loglevel);
}
*/
package jalview.util;
+import java.io.File;
import java.util.Map;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
import org.apache.logging.log4j.core.layout.PatternLayout;
public final static String SIMPLE_PATTERN = "%level - %m%n";
+ public final static String TIME_PATTERN = "%d{yyyy-MM-dd HH:mm:ss} %level - %m%n";
+
private static boolean init = false;
public static boolean isInit()
init(log4jLevel(myLevel));
}
+ public static void init(JLogger.LogLevel myLevel, File logfile)
+ {
+ init(log4jLevel(myLevel), logfile);
+ }
+
public static void init(Level myLevel)
{
+ init(myLevel, null);
+ }
+
+ public static void init(Level myLevel, File logfile)
+ {
if (init)
+ {
return;
+ }
try
{
// configure the root logger to stderr
ConfigurationBuilder<BuiltConfiguration> configBuilder = Log4j
.getConfigurationBuilder();
+ configBuilder.setStatusLevel(Level.INFO);
- configBuilder.setStatusLevel(Level.WARN);
-
+ // Console
String consoleLoggerName = "STDERR";
AppenderComponentBuilder appenderBuilder = configBuilder
.newAppender(consoleLoggerName, "Console");
appenderBuilder.add(Log4j.getThresholdFilterBuilder());
configBuilder.add(appenderBuilder);
- configBuilder.add(configBuilder.newRootLogger(myLevel)
- .add(configBuilder.newAppenderRef(consoleLoggerName)));
+ RootLoggerComponentBuilder root = configBuilder
+ .newRootLogger(myLevel);
+ root.add(configBuilder.newAppenderRef(consoleLoggerName));
+
+ if (logfile != null)
+ {
+ String fileLoggerName = "LOGFILE";
+ appenderBuilder = configBuilder.newAppender(fileLoggerName, "File")
+ .addAttribute("fileName", logfile.getAbsolutePath());
+ appenderBuilder.add(Log4j.getTimeLayoutBuilder());
+ appenderBuilder.add(Log4j.getThresholdFilterBuilder());
+
+ configBuilder.add(appenderBuilder);
+
+ root.add(configBuilder.newAppenderRef(fileLoggerName));
+ }
+ configBuilder.add(root);
Configurator.initialize(configBuilder.build());
return ConfigurationFactory.newConfigurationBuilder();
}
+ public static Layout getTimeLayout()
+ {
+ return PatternLayout.newBuilder().withPattern(TIME_PATTERN).build();
+ }
+
public static Layout getSimpleLayout()
{
return PatternLayout.newBuilder().withPattern(SIMPLE_PATTERN).build();
}
+ public static LayoutComponentBuilder getTimeLayoutBuilder()
+ {
+ return getConfigurationBuilder().newLayout("PatternLayout")
+ .addAttribute("pattern", Log4j.TIME_PATTERN);
+ }
+
public static LayoutComponentBuilder getSimpleLayoutBuilder()
{
return getConfigurationBuilder().newLayout("PatternLayout")
*/
package jalview.ws.jws2;
-import jalview.bin.Cache;
-import jalview.bin.Console;
-import jalview.gui.AlignFrame;
-import jalview.gui.Desktop;
-import jalview.gui.JvSwingUtils;
-import jalview.util.MessageManager;
-import jalview.ws.WSMenuEntryProviderI;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
-import jalview.ws.params.ParamDatastoreI;
-
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import compbio.ws.client.Services;
+import jalview.bin.Cache;
+import jalview.bin.Console;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.JvSwingUtils;
+import jalview.util.MessageManager;
+import jalview.ws.WSMenuEntryProviderI;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ParamDatastoreI;
/**
* discoverer for jws2 services. Follows the lightweight service discoverer
{
services = new Vector<>();
}
- jalview.bin.Console.outPrintln(
+ jalview.bin.Console.info(
"Discovered service: " + jwsservers + " " + service.toString());
// Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
// service2);
echo "Removing '$APPLICATIONS/$APP.app'"
/bin/rm -r "$APPLICATIONS/$APP.app"
echo "Syncing '$MOUNTEDAPP' to '$APPLICATIONS/'"
- rsync -avh "$MOUNTEDAPP" "$APPLICATIONS/"
+ rsync --delete -avh "$MOUNTEDAPP" "$APPLICATIONS/"
echo "Unmounting '/Volumes/$INSTALLERVOL'"
hdiutil detach "/Volumes/$INSTALLERVOL"
else
<versionLine x="85" y="109" text="version ${compiler:sys.version}" />
</text>
</splashScreen>
- <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir="${launcher:sys.launcherDirectory}" -Dinstaller.application_folder="${compiler:APPLICATION_FOLDER}" -Dchannel.app_name="${compiler:JALVIEW_APPLICATION_NAME}" -Dinstaller.icon="${compiler:PNG_ICON_FILE}" -Dinstaller.mac_icons="${compiler:MAC_ICONS_FILE}" -Dinstaller.logfile="~/.${compiler:LOG_FILE}"" arguments=""" """>
+ <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir="${launcher:sys.launcherDirectory}" -Dinstaller.application_folder="${compiler:APPLICATION_FOLDER}" -Dchannel.app_name="${compiler:JALVIEW_APPLICATION_NAME}" -Dinstaller.icon="${compiler:PNG_ICON_FILE}" -Dinstaller.mac_icons="${compiler:MAC_ICONS_FILE}" -Dinstaller.logfile="~/.${compiler:LOG_FILE}" -Dinstaller.logfile_append=true" arguments=""" """>
<classPath>
<archive location="getdown-launcher.jar" failOnError="false" />
<archive location="${compiler:GETDOWN_INSTALL_DIR}/getdown-launcher.jar" failOnError="false" />