Compiles message with "{}" arg patterns. @param msg Message pattern. @param args Values to pass. @return Compiled message with inlined arg values.
(String msg, Object[] args)
| 154 | * @return Compiled message with inlined arg values. |
| 155 | */ |
| 156 | private static String compile(String msg, Object[] args) { |
| 157 | int c = 0; |
| 158 | while(msg.contains("{}")) { |
| 159 | // Failsafe, shouldn't occur if logging is written correctly |
| 160 | if (c == args.length) |
| 161 | return msg; |
| 162 | // Replace arg in pattern |
| 163 | Object arg = args[c]; |
| 164 | String argStr = arg == null ? "null" : arg.toString(); |
| 165 | msg = msg.replaceFirst("\\{}", Matcher.quoteReplacement(argStr)); |
| 166 | c++; |
| 167 | } |
| 168 | return msg; |
| 169 | } |
| 170 | |
| 171 | static { |
| 172 | // Clear old log |