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,10 +54,12 @@ public abstract class Start | ||
54 | 54 | ||
55 | private static void prepareLogger() | 55 | private static void prepareLogger() |
56 | { | 56 | { |
57 | + System.setProperty("liteloaderFormatLog", "true"); | ||
58 | + | ||
57 | for (Handler handler : Start.logger.getParent().getHandlers()) | 59 | for (Handler handler : Start.logger.getParent().getHandlers()) |
58 | { | 60 | { |
59 | if (handler instanceof ConsoleHandler) | 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,7 +11,6 @@ import java.lang.reflect.Field; | ||
11 | import java.util.List; | 11 | import java.util.List; |
12 | import java.util.Properties; | 12 | import java.util.Properties; |
13 | import java.util.logging.FileHandler; | 13 | import java.util.logging.FileHandler; |
14 | -import java.util.logging.Formatter; | ||
15 | import java.util.logging.Level; | 14 | import java.util.logging.Level; |
16 | import java.util.logging.Logger; | 15 | import java.util.logging.Logger; |
17 | import java.util.logging.StreamHandler; | 16 | import java.util.logging.StreamHandler; |
@@ -107,7 +106,7 @@ class LiteLoaderBootstrap implements ILoaderBootstrap | @@ -107,7 +106,7 @@ class LiteLoaderBootstrap implements ILoaderBootstrap | ||
107 | * The mod enumerator instance | 106 | * The mod enumerator instance |
108 | */ | 107 | */ |
109 | private LiteLoaderEnumerator enumerator; | 108 | private LiteLoaderEnumerator enumerator; |
110 | - | 109 | + |
111 | /** | 110 | /** |
112 | * @param gameDirectory | 111 | * @param gameDirectory |
113 | * @param assetsDirectory | 112 | * @param assetsDirectory |
@@ -231,17 +230,15 @@ class LiteLoaderBootstrap implements ILoaderBootstrap | @@ -231,17 +230,15 @@ class LiteLoaderBootstrap implements ILoaderBootstrap | ||
231 | */ | 230 | */ |
232 | private void prepareLogger() throws SecurityException, IOException | 231 | private void prepareLogger() throws SecurityException, IOException |
233 | { | 232 | { |
234 | - Formatter logFormatter = new LiteLoaderLogFormatter(); | ||
235 | - | ||
236 | LiteLoaderBootstrap.logger.setUseParentHandlers(false); | 233 | LiteLoaderBootstrap.logger.setUseParentHandlers(false); |
237 | LiteLoaderBootstrap.useStdOut = System.getProperty("liteloader.log", "stderr").equalsIgnoreCase("stdout") || this.localProperties.getProperty("log", "stderr").equalsIgnoreCase("stdout"); | 234 | LiteLoaderBootstrap.useStdOut = System.getProperty("liteloader.log", "stderr").equalsIgnoreCase("stdout") || this.localProperties.getProperty("log", "stderr").equalsIgnoreCase("stdout"); |
238 | 235 | ||
239 | StreamHandler consoleHandler = useStdOut ? new com.mumfrey.liteloader.util.log.ConsoleHandler() : new java.util.logging.ConsoleHandler(); | 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 | LiteLoaderBootstrap.logger.addHandler(consoleHandler); | 238 | LiteLoaderBootstrap.logger.addHandler(consoleHandler); |
242 | 239 | ||
243 | FileHandler logFileHandler = new FileHandler(this.logFile.getAbsolutePath()); | 240 | FileHandler logFileHandler = new FileHandler(this.logFile.getAbsolutePath()); |
244 | - logFileHandler.setFormatter(logFormatter); | 241 | + logFileHandler.setFormatter(new LiteLoaderLogFormatter(true)); |
245 | LiteLoaderBootstrap.logger.addHandler(logFileHandler); | 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,24 +9,36 @@ import java.util.logging.LogRecord; | ||
9 | 9 | ||
10 | public class LiteLoaderLogFormatter extends Formatter | 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 | @Override | 21 | @Override |
15 | public String format(LogRecord logRecord) | 22 | public String format(LogRecord logRecord) |
16 | { | 23 | { |
17 | StringBuilder sb = new StringBuilder(); | 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 | else | 34 | else |
24 | - sb.append(" [").append(level.toString().toUpperCase()).append("] "); | 35 | + { |
36 | + sb.append("LiteLoader> "); | ||
37 | + } | ||
25 | 38 | ||
26 | sb.append(logRecord.getMessage()); | 39 | sb.append(logRecord.getMessage()); |
27 | sb.append('\n'); | 40 | sb.append('\n'); |
28 | Throwable th = logRecord.getThrown(); | 41 | Throwable th = logRecord.getThrown(); |
29 | - | ||
30 | if (th != null) | 42 | if (th != null) |
31 | { | 43 | { |
32 | StringWriter stringWriter = new StringWriter(); | 44 | StringWriter stringWriter = new StringWriter(); |
@@ -36,4 +48,4 @@ public class LiteLoaderLogFormatter extends Formatter | @@ -36,4 +48,4 @@ public class LiteLoaderLogFormatter extends Formatter | ||
36 | 48 | ||
37 | return sb.toString(); | 49 | return sb.toString(); |
38 | } | 50 | } |
39 | -} | 51 | +} |
40 | \ No newline at end of file | 52 | \ No newline at end of file |