Log ByteBuf content properly

pull/1705/head
Nikita Koksharov 6 years ago
parent 31d47c2517
commit dc92cef238

@ -34,7 +34,7 @@ public class LogHelper {
private LogHelper() { private LogHelper() {
} }
public static <T> String toString(T object) { public static String toString(Object object) {
if (object == null) { if (object == null) {
return "null"; return "null";
} else if (object instanceof String) { } else if (object instanceof String) {
@ -44,8 +44,14 @@ public class LogHelper {
} else if (object instanceof Collection) { } else if (object instanceof Collection) {
return toCollectionString((Collection<?>) object); return toCollectionString((Collection<?>) object);
} else if (object instanceof CommandData) { } else if (object instanceof CommandData) {
CommandData cd = (CommandData)object; CommandData<?, ?> cd = (CommandData<?, ?>)object;
return cd.getCommand() + ", params: " + LogHelper.toString(cd.getParams()); return cd.getCommand() + ", params: " + LogHelper.toString(cd.getParams());
} else if (object instanceof ByteBuf) {
final ByteBuf byteBuf = (ByteBuf) object;
if (byteBuf.refCnt() > 0) {
return byteBuf.toString(0, byteBuf.writerIndex(), CharsetUtil.UTF_8);
}
return byteBuf.toString();
} else { } else {
return String.valueOf(object); return String.valueOf(object);
} }

Loading…
Cancel
Save