comparison graal/com.oracle.max.criutils/src/com/oracle/max/criutils/TTY.java @ 5328:e4e02131c58b

log file (i.e. -G:LogFile=log.txt option) now used for TTY output as well
author Doug Simon <doug.simon@oracle.com>
date Mon, 30 Apr 2012 20:28:49 +0200
parents bc8527f3071c
children 4d7175cf3526
comparison
equal deleted inserted replaced
5327:28577a53d3a7 5328:e4e02131c58b
87 out.set(previous); 87 out.set(previous);
88 } 88 }
89 } 89 }
90 } 90 }
91 91
92 public static final String MAX_TTY_LOG_FILE_PROPERTY = "max.tty.file";
93
94 public static PrintStream cachedOut; 92 public static PrintStream cachedOut;
95 93
96 public static void initialize() { 94 public static void initialize(PrintStream ps) {
97 cachedOut = System.out; 95 cachedOut = ps;
98 } 96 }
99 97
100 private static LogStream createLog() { 98 private static LogStream createLog() {
101 if (cachedOut == null) { 99 if (cachedOut == null) {
102 // In case initialize() was not called. 100 // In case initialize() was not called.
103 cachedOut = System.out; 101 cachedOut = System.out;
104 } 102 }
105 PrintStream newOut = cachedOut; 103 return new LogStream(cachedOut);
106 String value = System.getProperty(MAX_TTY_LOG_FILE_PROPERTY);
107 if (value != null) {
108 try {
109 newOut = new PrintStream(new FileOutputStream(value));
110 } catch (FileNotFoundException e) {
111 System.err.println("Could not open log file " + value + ": " + e);
112 }
113 }
114 return new LogStream(newOut);
115 } 104 }
116 105
117 private static final ThreadLocal<LogStream> out = new ThreadLocal<LogStream>() { 106 private static final ThreadLocal<LogStream> out = new ThreadLocal<LogStream>() {
118 @Override 107 @Override
119 protected LogStream initialValue() { 108 protected LogStream initialValue() {