Created
November 3, 2014 18:09
-
-
Save sehugg/9bd6f0536afb6b6458b4 to your computer and use it in GitHub Desktop.
Console logging for RoboVM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.robovm.apple.foundation.Foundation; | |
public class FoundationLogPrintStream extends LoggingPrintStream | |
{ | |
@Override | |
public void log(String text) | |
{ | |
Foundation.log(text); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call this from createApplication() | |
private void setupSystemLogging () { | |
System.setErr(new FoundationLogPrintStream()); | |
System.err.println("System.err logging"); | |
System.setOut(new FoundationLogPrintStream()); | |
System.out.println("System.out logging"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.PrintStream; | |
public abstract class LoggingPrintStream extends PrintStream | |
{ | |
StringBuffer st = new StringBuffer(); | |
// | |
public LoggingPrintStream() | |
{ | |
super(new OutputStream() | |
{ | |
@Override | |
public void write(int arg0) throws IOException | |
{ | |
} | |
}); | |
} | |
public abstract void log(String text); | |
public void write(char ch) | |
{ | |
if (ch == 0xa) | |
{ | |
} else | |
st.append(ch); | |
} | |
@Override | |
public void flush() | |
{ | |
if (st.length() > 0) | |
{ | |
log(st.toString()); | |
st.setLength(0); | |
} | |
} | |
// | |
@Override | |
public void print(char[] s) | |
{ | |
for (char ch : s) | |
write(ch); | |
} | |
@Override | |
public void print(boolean b) | |
{ | |
print(b+""); | |
} | |
@Override | |
public void print(char c) | |
{ | |
write(c); | |
} | |
@Override | |
public void print(double d) | |
{ | |
print(d+""); | |
} | |
@Override | |
public void print(float f) | |
{ | |
print(f+""); | |
} | |
@Override | |
public void print(int i) | |
{ | |
print(i+""); | |
} | |
public void print(long l) | |
{ | |
print(l+""); | |
} | |
@Override | |
public void print(Object obj) | |
{ | |
print((obj+"").toCharArray()); | |
} | |
@Override | |
public void print(String s) | |
{ | |
print((s+"").toCharArray()); | |
} | |
@Override | |
public void println() | |
{ | |
flush(); | |
} | |
@Override | |
public void println(boolean x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(char x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(char[] x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(double x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(float x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(int x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(long x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(Object x) | |
{ | |
print(x); | |
flush(); | |
} | |
@Override | |
public void println(String x) | |
{ | |
print(x); | |
flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment