Commit 543970266379ac37e69058faf10cb05e3758edde
1 parent
cc303e4e
LiteLoader 1.6.4_02 - dev only - change logger to play better with new launcher …
…(don't unnecessarily prepend date/time/level)
Showing
3 changed files
with
27 additions
and
16 deletions
debug/com/mumfrey/liteloader/debug/Start.java
... | ... | @@ -54,10 +54,12 @@ public abstract class Start |
54 | 54 | |
55 | 55 | private static void prepareLogger() |
56 | 56 | { |
57 | + System.setProperty("liteloaderFormatLog", "true"); | |
58 | + | |
57 | 59 | for (Handler handler : Start.logger.getParent().getHandlers()) |
58 | 60 | { |
59 | 61 | if (handler instanceof ConsoleHandler) |
60 | - handler.setFormatter(new LiteLoaderLogFormatter()); | |
62 | + handler.setFormatter(new LiteLoaderLogFormatter(false)); | |
61 | 63 | } |
62 | 64 | } |
63 | 65 | } | ... | ... |
java/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
... | ... | @@ -11,7 +11,6 @@ import java.lang.reflect.Field; |
11 | 11 | import java.util.List; |
12 | 12 | import java.util.Properties; |
13 | 13 | import java.util.logging.FileHandler; |
14 | -import java.util.logging.Formatter; | |
15 | 14 | import java.util.logging.Level; |
16 | 15 | import java.util.logging.Logger; |
17 | 16 | import java.util.logging.StreamHandler; |
... | ... | @@ -107,7 +106,7 @@ class LiteLoaderBootstrap implements ILoaderBootstrap |
107 | 106 | * The mod enumerator instance |
108 | 107 | */ |
109 | 108 | private LiteLoaderEnumerator enumerator; |
110 | - | |
109 | + | |
111 | 110 | /** |
112 | 111 | * @param gameDirectory |
113 | 112 | * @param assetsDirectory |
... | ... | @@ -231,17 +230,15 @@ class LiteLoaderBootstrap implements ILoaderBootstrap |
231 | 230 | */ |
232 | 231 | private void prepareLogger() throws SecurityException, IOException |
233 | 232 | { |
234 | - Formatter logFormatter = new LiteLoaderLogFormatter(); | |
235 | - | |
236 | 233 | LiteLoaderBootstrap.logger.setUseParentHandlers(false); |
237 | 234 | LiteLoaderBootstrap.useStdOut = System.getProperty("liteloader.log", "stderr").equalsIgnoreCase("stdout") || this.localProperties.getProperty("log", "stderr").equalsIgnoreCase("stdout"); |
238 | 235 | |
239 | 236 | StreamHandler consoleHandler = useStdOut ? new com.mumfrey.liteloader.util.log.ConsoleHandler() : new java.util.logging.ConsoleHandler(); |
240 | - consoleHandler.setFormatter(logFormatter); | |
237 | + consoleHandler.setFormatter(new LiteLoaderLogFormatter(false)); | |
241 | 238 | LiteLoaderBootstrap.logger.addHandler(consoleHandler); |
242 | 239 | |
243 | 240 | FileHandler logFileHandler = new FileHandler(this.logFile.getAbsolutePath()); |
244 | - logFileHandler.setFormatter(logFormatter); | |
241 | + logFileHandler.setFormatter(new LiteLoaderLogFormatter(true)); | |
245 | 242 | LiteLoaderBootstrap.logger.addHandler(logFileHandler); |
246 | 243 | } |
247 | 244 | ... | ... |
java/com/mumfrey/liteloader/util/log/LiteLoaderLogFormatter.java
... | ... | @@ -9,24 +9,36 @@ import java.util.logging.LogRecord; |
9 | 9 | |
10 | 10 | public class LiteLoaderLogFormatter extends Formatter |
11 | 11 | { |
12 | - private SimpleDateFormat simpleDateFormatLogFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
12 | + private static SimpleDateFormat simpleDateFormatLogFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
13 | + | |
14 | + private boolean prepend = false; | |
13 | 15 | |
16 | + public LiteLoaderLogFormatter(boolean prependDateAndTime) | |
17 | + { | |
18 | + this.prepend = prependDateAndTime || System.getProperty("liteloaderFormatLog") != null; | |
19 | + } | |
20 | + | |
14 | 21 | @Override |
15 | 22 | public String format(LogRecord logRecord) |
16 | 23 | { |
17 | 24 | StringBuilder sb = new StringBuilder(); |
18 | - sb.append(this.simpleDateFormatLogFormatter.format(Long.valueOf(logRecord.getMillis()))); | |
19 | - Level level = logRecord.getLevel(); | |
20 | - | |
21 | - if (level == Level.SEVERE) | |
22 | - sb.append(" [").append(level.getLocalizedName()).append("] "); | |
25 | + if (this.prepend) | |
26 | + { | |
27 | + sb.append(this.simpleDateFormatLogFormatter.format(Long.valueOf(logRecord.getMillis()))); | |
28 | + Level level = logRecord.getLevel(); | |
29 | + if (level == Level.SEVERE) | |
30 | + sb.append(" [").append(level.getLocalizedName()).append("] "); | |
31 | + else | |
32 | + sb.append(" [").append(level.toString().toUpperCase()).append("] "); | |
33 | + } | |
23 | 34 | else |
24 | - sb.append(" [").append(level.toString().toUpperCase()).append("] "); | |
35 | + { | |
36 | + sb.append("LiteLoader> "); | |
37 | + } | |
25 | 38 | |
26 | 39 | sb.append(logRecord.getMessage()); |
27 | 40 | sb.append('\n'); |
28 | 41 | Throwable th = logRecord.getThrown(); |
29 | - | |
30 | 42 | if (th != null) |
31 | 43 | { |
32 | 44 | StringWriter stringWriter = new StringWriter(); |
... | ... | @@ -36,4 +48,4 @@ public class LiteLoaderLogFormatter extends Formatter |
36 | 48 | |
37 | 49 | return sb.toString(); |
38 | 50 | } |
39 | -} | |
51 | +} | |
40 | 52 | \ No newline at end of file | ... | ... |