New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.out being swallowed #37
Comments
Here's the output from the launcher.log
|
Unfortunately, Getdown can't pass through stdout and stderr because it needs to eventually terminate its own process and leave the app process running. If it did not immediately close stdout and stderr, then the app process would hang on some platforms as soon as the Getdown launcher process exited. This means that your app has to redirect System.out and System.err to a file when it starts up if you want to use those for logging. The alternative would be to have the Getdown process stay alive for the lifetime of the app process, but then you'd have two whole JVMs running instead of just one, which is a huge memory waste. |
I am confronted to the same problem. I tried to add output redirects on the javaw.exe command line but it doesn't seem to work:
Perhap's it will work if we launch cmd.exe instead of direct javaw.exe ? |
You can't use shell mechanisms to redirect your app's output because Getdown does not use a shell to run your app. You have to redirect the output from inside your Java program. Here's an example from the Bang! Howdy client which should give you the idea: /**
* Redirects the output of the application to the specified log file and configures our various
* logging systems.
*/
public static void configureLog (String logfile)
{
// potentially redirect stdout and stderr to a log file
File nlog = null;
if (System.getProperty("no_log_redir") == null) {
// first delete any previous previous log file
File olog = new File(BangClient.localDataDir("old-" + logfile));
if (olog.exists()) {
olog.delete();
}
// next rename the previous log file
nlog = new File(BangClient.localDataDir(logfile));
if (nlog.exists()) {
nlog.renameTo(olog);
}
// and now redirect our output
try {
PrintStream logOut = new PrintStream(new FileOutputStream(nlog), true);
System.setOut(logOut);
System.setErr(logOut);
} catch (IOException ioe) {
log.warning("Failed to open debug log", "path", nlog, "error", ioe);
}
}
// ...
// if we've redirected our log output, note where to
if (nlog != null) {
log.info("Logging to '" + nlog + "'.");
}
}
public static void main (String[] args)
{
// configure our debug log
configureLog("bang.log");
// ...
} |
That's a big issue unfortunately. If the logging system fails to initialise I think it's already been suggested but I would also suggest allowing On Thu, 11 Feb 2016, 20:36 Michael Bayne notifications@github.com wrote:
|
If the first action in main() is to redirect stdout/stderr then any output will go there from any logging system or whatnot. Wrapping the process in a shell is not something that can be done in a cross-platform way. There is no shell that exists on all platforms. |
You're right of course, the dev would need to define which shell is to be The problem with some apps (one of my current ones) is that the main() It's possibly getting beyond the scope of what you originally intended for On Sat, 13 Feb 2016, 22:13 Michael Bayne notifications@github.com wrote:
|
Even in a situation like that, you should be able to write a shim class: public class RedirectAndRun {
public static void main (String[] args) {
// redirect System.out, System.err
RealApp.main(args);
}
} and bundle that with your app and run that class instead of having Getdown And as an added bonus, the log redirecting will be cross-platform. |
The System.out prints are getting swallowed by the getdown app. I can see that my application is launching successfully and writing a test file to the filesystem but can't see any stdout in either the launcher.log or in the console I launch the app from. I guess it's something to do with log4j config?
The text was updated successfully, but these errors were encountered: