From 88b49fba0ea8249a4842e28623e5095509ec8767 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 5 Jul 2016 14:24:31 +0300 Subject: [PATCH] do not ignore attachments by default in Teamcity --- .../openapi/diagnostic/DefaultLogger.java | 12 +------ .../intellij/openapi/diagnostic/Logger.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/diagnostic/DefaultLogger.java b/platform/util/src/com/intellij/openapi/diagnostic/DefaultLogger.java index 0943a0775ae1..ba7470cb3494 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/DefaultLogger.java +++ b/platform/util/src/com/intellij/openapi/diagnostic/DefaultLogger.java @@ -17,7 +17,6 @@ package com.intellij.openapi.diagnostic; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ExceptionUtil; -import com.intellij.util.Function; import org.apache.log4j.Level; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -81,17 +80,8 @@ public class DefaultLogger extends Logger { //noinspection ThrowableResultOfMethodCallIgnored Throwable rootCause = t == null ? null : ExceptionUtil.getRootCause(t); if (rootCause instanceof ExceptionWithAttachments) { - return "\nAttachments:" + StringUtil.join(((ExceptionWithAttachments)rootCause).getAttachments(), - new Function() { - @Override - public String fun(Attachment attachment) { - return attachment.getPath() + "\n" + attachment.getDisplayText(); - } - }, - "\n----\n"); + return "\nAttachments:" + StringUtil.join(((ExceptionWithAttachments)rootCause).getAttachments(), ATTACHMENT_TO_STRING, "\n----\n"); } return ""; } - - } diff --git a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java index dae2659cd16c..03ebe3270941 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/Logger.java +++ b/platform/util/src/com/intellij/openapi/diagnostic/Logger.java @@ -17,6 +17,8 @@ package com.intellij.openapi.diagnostic; import com.intellij.util.ArrayUtil; import com.intellij.util.ExceptionUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.apache.log4j.Level; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NonNls; @@ -27,19 +29,21 @@ import java.lang.reflect.Constructor; public abstract class Logger { public interface Factory { - Logger getLoggerInstance(String category); + @NotNull + Logger getLoggerInstance(@NotNull String category); } private static class DefaultFactory implements Factory { + @NotNull @Override - public Logger getLoggerInstance(String category) { + public Logger getLoggerInstance(@NotNull String category) { return new DefaultLogger(category); } } private static Factory ourFactory = new DefaultFactory(); - public static void setFactory(Class factory) { + public static void setFactory(@NotNull Class factory) { if (isInitialized()) { if (factory.isInstance(ourFactory)) { return; @@ -65,12 +69,13 @@ public abstract class Logger { return !(ourFactory instanceof DefaultFactory); } - public static Logger getInstance(@NonNls String category) { + @NotNull + public static Logger getInstance(@NotNull @NonNls String category) { return ourFactory.getLoggerInstance(category); } @NotNull - public static Logger getInstance(Class cl) { + public static Logger getInstance(@NotNull Class cl) { return getInstance("#" + cl.getName()); } @@ -82,12 +87,12 @@ public abstract class Logger { public abstract void debug(@NonNls String message, @Nullable Throwable t); - public void debug(@NotNull String message, Object... details) { + public void debug(@NotNull String message, @NotNull Object... details) { if (isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append(message); for (Object detail : details) { - sb.append(String.valueOf(detail)); + sb.append(detail); } debug(sb.toString()); } @@ -130,11 +135,18 @@ public abstract class Logger { error(String.valueOf(message)); } - public void error(@NonNls String message, Attachment... attachments) { - error(message); + static final Function ATTACHMENT_TO_STRING = new Function() { + @Override + public String fun(Attachment attachment) { + return attachment.getPath() + "\n" + attachment.getDisplayText(); + } + }; + + public void error(@NonNls String message, @NotNull Attachment... attachments) { + error(message, null, ContainerUtil.map2Array(attachments, String.class, ATTACHMENT_TO_STRING)); } - public void error(@NonNls String message, @NonNls String... details) { + public void error(@NonNls String message, @NonNls @NotNull String... details) { error(message, new Throwable(), details); }