From 7a722217ab3d9953518f4c1c7f61c1b9d5f08097 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Tue, 28 Nov 2023 15:05:42 +0800 Subject: [PATCH] fix AnsiLog static init may error. #2740 --- .../com/taobao/arthas/common/AnsiLog.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/taobao/arthas/common/AnsiLog.java b/common/src/main/java/com/taobao/arthas/common/AnsiLog.java index e9d4e903bd6..2ff31adf07a 100644 --- a/common/src/main/java/com/taobao/arthas/common/AnsiLog.java +++ b/common/src/main/java/com/taobao/arthas/common/AnsiLog.java @@ -53,16 +53,20 @@ public abstract class AnsiLog { private static final String ERROR_COLOR_PREFIX = "[" + colorStr("ERROR", RED) + "] "; static { - if (System.console() != null) { - enableColor = true; - // windows dos, do not support color - if (OSUtils.isWindows()) { - enableColor = false; + try { + if (System.console() != null) { + enableColor = true; + // windows dos, do not support color + if (OSUtils.isWindows()) { + enableColor = false; + } } - } - // cygwin and mingw support color - if (OSUtils.isCygwinOrMinGW()) { - enableColor = true; + // cygwin and mingw support color + if (OSUtils.isCygwinOrMinGW()) { + enableColor = true; + } + } catch (Throwable t) { + // ignore } }