@Test void translate() { LogEvent logEvent = new LogEvent(LogLevel.ERROR, "hello {} world {}", new Object[]{ "one", "two" }, null); LogEvent translatedLogEvent = LogUtils.translate(logEvent, "hello2 {} world2 {}"); assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage()); assertArrayEquals(new Object[]{ "one", "two" }, translatedLogEvent.getArgumentArray()); translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0} world2 {1}"); assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage()); assertArrayEquals(new Object[]{ "one", "two" }, translatedLogEvent.getArgumentArray()); translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1} world2 {0}"); assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage()); assertArrayEquals(new Object[]{ "two", "one" }, translatedLogEvent.getArgumentArray()); translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0}"); assertEquals("hello2 {}", translatedLogEvent.getMessage()); assertArrayEquals(new Object[]{ "one", "two" }, translatedLogEvent.getArgumentArray()); translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1}"); assertEquals("hello2 {}", translatedLogEvent.getMessage()); assertArrayEquals(new Object[]{ "two", "two" }, translatedLogEvent.getArgumentArray()); }
public static LogEvent translate(LogEvent logEvent, String translatedMessage) { if (translatedMessage != null) { MessageParser parser = new MessageParser(translatedMessage, true); Object[] defaultArguments = logEvent.getArgumentArray(); Object[] arguments = new Object[defaultArguments.length]; StringBuilder message = new StringBuilder(); int index = 0; for (MessageElement element = parser.next(); element != null; element = parser.next()) { if (element instanceof MessageIndex) { message.append(MessageParser.ARGUMENT_STR); arguments[index++] = defaultArguments[((MessageIndex) element).getIndex()]; } else { message.append(element.getString()); } } for (; index < arguments.length; ++index) { arguments[index] = defaultArguments[index]; } return new LogEvent(logEvent.getMarker(), logEvent.getLevel(), message.toString(), arguments, logEvent.getThrowable(), logEvent.getTimeStamp()); } return logEvent; }
LogUtils { public static LogEvent translate(LogEvent logEvent, String translatedMessage) { if (translatedMessage != null) { MessageParser parser = new MessageParser(translatedMessage, true); Object[] defaultArguments = logEvent.getArgumentArray(); Object[] arguments = new Object[defaultArguments.length]; StringBuilder message = new StringBuilder(); int index = 0; for (MessageElement element = parser.next(); element != null; element = parser.next()) { if (element instanceof MessageIndex) { message.append(MessageParser.ARGUMENT_STR); arguments[index++] = defaultArguments[((MessageIndex) element).getIndex()]; } else { message.append(element.getString()); } } for (; index < arguments.length; ++index) { arguments[index] = defaultArguments[index]; } return new LogEvent(logEvent.getMarker(), logEvent.getLevel(), message.toString(), arguments, logEvent.getThrowable(), logEvent.getTimeStamp()); } return logEvent; } }
LogUtils { public static LogEvent translate(LogEvent logEvent, String translatedMessage) { if (translatedMessage != null) { MessageParser parser = new MessageParser(translatedMessage, true); Object[] defaultArguments = logEvent.getArgumentArray(); Object[] arguments = new Object[defaultArguments.length]; StringBuilder message = new StringBuilder(); int index = 0; for (MessageElement element = parser.next(); element != null; element = parser.next()) { if (element instanceof MessageIndex) { message.append(MessageParser.ARGUMENT_STR); arguments[index++] = defaultArguments[((MessageIndex) element).getIndex()]; } else { message.append(element.getString()); } } for (; index < arguments.length; ++index) { arguments[index] = defaultArguments[index]; } return new LogEvent(logEvent.getMarker(), logEvent.getLevel(), message.toString(), arguments, logEvent.getThrowable(), logEvent.getTimeStamp()); } return logEvent; } private  LogUtils(); }
LogUtils { public static LogEvent translate(LogEvent logEvent, String translatedMessage) { if (translatedMessage != null) { MessageParser parser = new MessageParser(translatedMessage, true); Object[] defaultArguments = logEvent.getArgumentArray(); Object[] arguments = new Object[defaultArguments.length]; StringBuilder message = new StringBuilder(); int index = 0; for (MessageElement element = parser.next(); element != null; element = parser.next()) { if (element instanceof MessageIndex) { message.append(MessageParser.ARGUMENT_STR); arguments[index++] = defaultArguments[((MessageIndex) element).getIndex()]; } else { message.append(element.getString()); } } for (; index < arguments.length; ++index) { arguments[index] = defaultArguments[index]; } return new LogEvent(logEvent.getMarker(), logEvent.getLevel(), message.toString(), arguments, logEvent.getThrowable(), logEvent.getTimeStamp()); } return logEvent; } private  LogUtils(); static LogEvent newLogEvent(Marker marker, LogLevel level, String message, Object[] argumentArray,
        Throwable throwable); static LogEvent newLogEvent(Marker marker, LogLevel level, String message, Object[] argumentArray,
        Throwable throwable, long timeStamp); static LogEvent translate(LogEvent logEvent, String translatedMessage); }
LogUtils { public static LogEvent translate(LogEvent logEvent, String translatedMessage) { if (translatedMessage != null) { MessageParser parser = new MessageParser(translatedMessage, true); Object[] defaultArguments = logEvent.getArgumentArray(); Object[] arguments = new Object[defaultArguments.length]; StringBuilder message = new StringBuilder(); int index = 0; for (MessageElement element = parser.next(); element != null; element = parser.next()) { if (element instanceof MessageIndex) { message.append(MessageParser.ARGUMENT_STR); arguments[index++] = defaultArguments[((MessageIndex) element).getIndex()]; } else { message.append(element.getString()); } } for (; index < arguments.length; ++index) { arguments[index] = defaultArguments[index]; } return new LogEvent(logEvent.getMarker(), logEvent.getLevel(), message.toString(), arguments, logEvent.getThrowable(), logEvent.getTimeStamp()); } return logEvent; } private  LogUtils(); static LogEvent newLogEvent(Marker marker, LogLevel level, String message, Object[] argumentArray,
        Throwable throwable); static LogEvent newLogEvent(Marker marker, LogLevel level, String message, Object[] argumentArray,
        Throwable throwable, long timeStamp); static LogEvent translate(LogEvent logEvent, String translatedMessage);  }