log launcher into a file before router starts, launcher.log. Get rid of system.out logging.
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
2022-05-8 idk
|
2022-05-8 idk
|
||||||
* Add translations for Arabic, German, French, Italian, Japanes, Portuguese, Russian,
|
* Add translations for Arabic, German, French, Italian, Japanese, Portuguese, Russian,
|
||||||
and Chinese.
|
and Chinese.
|
||||||
* Add support for I2P+ Router Console detection. Not an endorsement of I2P+, just
|
* Add support for I2P+ Router Console detection. Not an endorsement of I2P+, just
|
||||||
a convenience reuested by a helpful user.
|
a convenience requested by a helpful user.
|
||||||
* The build system has been radically improved in order to be simpler to set up and
|
* The build system has been radically improved in order to be simpler to set up and
|
||||||
configure.
|
configure.
|
||||||
* Fixed a bug where the build deleted a config file.
|
* Fixed a bug where the build deleted a config file.
|
||||||
|
@ -5,8 +5,8 @@ export JNA_VERSION=5.10.0
|
|||||||
|
|
||||||
#Comment this out to build from an alternate branch or
|
#Comment this out to build from an alternate branch or
|
||||||
# the tip of the master branch.
|
# the tip of the master branch.
|
||||||
I2P_VERSION=1.7.5
|
I2P_VERSION=1.7.6
|
||||||
export I2P_VERSION=1.7.5
|
export I2P_VERSION=1.7.6
|
||||||
VERSION=i2p-jpackage-1.7.1
|
VERSION=i2p-jpackage-1.7.1
|
||||||
export VERSION="$VERSION"
|
export VERSION="$VERSION"
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ import java.io.*;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
import net.i2p.crypto.*;
|
import net.i2p.crypto.*;
|
||||||
|
|
||||||
@ -28,12 +31,33 @@ import static net.i2p.update.UpdateType.*;
|
|||||||
* router.pid - the pid of the java process.
|
* router.pid - the pid of the java process.
|
||||||
*/
|
*/
|
||||||
public class WinLauncher {
|
public class WinLauncher {
|
||||||
|
static Logger logger = Logger.getLogger("launcherlog");
|
||||||
|
static FileHandler fh = new FileHandler(logFile().toString());
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// This block configure the logger with handler and formatter
|
||||||
|
fh = new FileHandler("C:/temp/test/MyLogFile.log");
|
||||||
|
logger.addHandler(fh);
|
||||||
|
SimpleFormatter formatter = new SimpleFormatter();
|
||||||
|
fh.setFormatter(formatter);
|
||||||
|
|
||||||
|
// the following statement is used to log any messages
|
||||||
|
logger.info("My first log");
|
||||||
|
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
File programs = selectProgramFile();
|
File programs = selectProgramFile();
|
||||||
if (!programs.exists())
|
if (!programs.exists())
|
||||||
programs.mkdirs();
|
programs.mkdirs();
|
||||||
else if (!programs.isDirectory()) {
|
else if (!programs.isDirectory()) {
|
||||||
System.err.println(programs + " exists but is not a directory. Please get it out of the way");
|
logger.warning(programs + " exists but is not a directory. Please get it out of the way");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,24 +65,24 @@ public class WinLauncher {
|
|||||||
if (!home.exists())
|
if (!home.exists())
|
||||||
home.mkdirs();
|
home.mkdirs();
|
||||||
else if (!home.isDirectory()) {
|
else if (!home.isDirectory()) {
|
||||||
System.err.println(home + " exists but is not a directory. Please get it out of the way");
|
logger.warning(home + " exists but is not a directory. Please get it out of the way");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.setProperty("i2p.dir.base", programs.getAbsolutePath());
|
System.setProperty("i2p.dir.base", programs.getAbsolutePath());
|
||||||
System.setProperty("i2p.dir.config", home.getAbsolutePath());
|
System.setProperty("i2p.dir.config", home.getAbsolutePath());
|
||||||
System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid()));
|
System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid()));
|
||||||
System.out.println("\t" + System.getProperty("i2p.dir.base") + "\n\t" + System.getProperty("i2p.dir.config")
|
logger.info("\t" + System.getProperty("i2p.dir.base") + "\n\t" + System.getProperty("i2p.dir.config")
|
||||||
+ "\n\t" + System.getProperty("router.pid"));
|
+ "\n\t" + System.getProperty("router.pid"));
|
||||||
|
|
||||||
// do a quick check to see of port 7657 is already occupied
|
// do a quick check to see of port 7657 is already occupied
|
||||||
if (i2pIsRunning()) {
|
if (i2pIsRunning()) {
|
||||||
System.err.println("I2P is already running");
|
logger.warning("I2P is already running");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wupp.i2pRouter = new Router(System.getProperties());
|
// wupp.i2pRouter = new Router(System.getProperties());
|
||||||
System.out.println("Router is configured");
|
logger.info("Router is configured");
|
||||||
|
|
||||||
Thread registrationThread = new Thread(REGISTER_UPP);
|
Thread registrationThread = new Thread(REGISTER_UPP);
|
||||||
registrationThread.setName("UPP Registration");
|
registrationThread.setName("UPP Registration");
|
||||||
@ -132,12 +156,12 @@ public class WinLauncher {
|
|||||||
File local = new File(appData, "Local");
|
File local = new File(appData, "Local");
|
||||||
File i2p;
|
File i2p;
|
||||||
i2p = new File(local, "I2P");
|
i2p = new File(local, "I2P");
|
||||||
System.out.println("Windows jpackage wrapper started, using: " + i2p + " as base config");
|
logger.info("Windows jpackage wrapper started, using: " + i2p + " as base config");
|
||||||
return i2p.getAbsoluteFile();
|
return i2p.getAbsoluteFile();
|
||||||
} else {
|
} else {
|
||||||
File jrehome = new File(System.getProperty("java.home"));
|
File jrehome = new File(System.getProperty("java.home"));
|
||||||
File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p");
|
File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p");
|
||||||
System.out.println("Linux portable jpackage wrapper started, using: " + programs + " as base config");
|
logger.info("Linux portable jpackage wrapper started, using: " + programs + " as base config");
|
||||||
return programs.getAbsoluteFile();
|
return programs.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,13 +180,20 @@ public class WinLauncher {
|
|||||||
if (SystemVersion.isWindows()) {
|
if (SystemVersion.isWindows()) {
|
||||||
File jrehome = new File(System.getProperty("java.home"));
|
File jrehome = new File(System.getProperty("java.home"));
|
||||||
File programs = jrehome.getParentFile();
|
File programs = jrehome.getParentFile();
|
||||||
System.out.println("Windows portable jpackage wrapper found, using: " + programs + " as working config");
|
logger.info("Windows portable jpackage wrapper found, using: " + programs + " as working config");
|
||||||
return programs.getAbsoluteFile();
|
return programs.getAbsoluteFile();
|
||||||
} else {
|
} else {
|
||||||
File jrehome = new File(System.getProperty("java.home"));
|
File jrehome = new File(System.getProperty("java.home"));
|
||||||
File programs = new File(jrehome.getParentFile().getParentFile(), "i2p");
|
File programs = new File(jrehome.getParentFile().getParentFile(), "i2p");
|
||||||
System.out.println("Linux portable jpackage wrapper found, using: " + programs + " as working config");
|
logger.info("Linux portable jpackage wrapper found, using: " + programs + " as working config");
|
||||||
return programs.getAbsoluteFile();
|
return programs.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File logFile() {
|
||||||
|
File log = new File(selectProgramFile(), "log");
|
||||||
|
if (!log.exists())
|
||||||
|
log.mkdirs();
|
||||||
|
return new File(log, "launcher.log");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ class WinUpdateProcess implements Runnable {
|
|||||||
private final RouterContext ctx;
|
private final RouterContext ctx;
|
||||||
private final Supplier<String> versionSupplier;
|
private final Supplier<String> versionSupplier;
|
||||||
private final Supplier<File> fileSupplier;
|
private final Supplier<File> fileSupplier;
|
||||||
|
private final Log _log;
|
||||||
|
|
||||||
WinUpdateProcess(RouterContext ctx, Supplier<String> versionSupplier, Supplier<File> fileSupplier) {
|
WinUpdateProcess(RouterContext ctx, Supplier<String> versionSupplier, Supplier<File> fileSupplier) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.versionSupplier = versionSupplier;
|
this.versionSupplier = versionSupplier;
|
||||||
this.fileSupplier = fileSupplier;
|
this.fileSupplier = fileSupplier;
|
||||||
|
this._log = ctx.logManager().getLog(WinUpdateProcess.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File workDir() throws IOException {
|
private File workDir() throws IOException {
|
||||||
@ -24,7 +26,7 @@ class WinUpdateProcess implements Runnable {
|
|||||||
if (workDir.exists()) {
|
if (workDir.exists()) {
|
||||||
if (workDir.isFile())
|
if (workDir.isFile())
|
||||||
throw new IOException(workDir + " exists but is a file, get it out of the way");
|
throw new IOException(workDir + " exists but is a file, get it out of the way");
|
||||||
return null;
|
return workDir;
|
||||||
} else {
|
} else {
|
||||||
workDir.mkdirs();
|
workDir.mkdirs();
|
||||||
}
|
}
|
||||||
@ -57,7 +59,7 @@ class WinUpdateProcess implements Runnable {
|
|||||||
try {
|
try {
|
||||||
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
_log.Error("Unable to run update-program in background. Update will fail.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we cant write to the log file and we're on Windows, use the elevator to
|
// If we cant write to the log file and we're on Windows, use the elevator to
|
||||||
@ -72,7 +74,7 @@ class WinUpdateProcess implements Runnable {
|
|||||||
try {
|
try {
|
||||||
runUpdateInstaller();
|
runUpdateInstaller();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.out.println("Error running updater, update may fail." + ioe);
|
_log.Error("Error running updater, update may fail." + ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user