mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
set arthas logs directory to /tmp/logs, when user.home is not writeable. #572
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ class ClassDumpTransformer implements ClassFileTransformer {
|
||||
public ClassDumpTransformer(Set<Class<?>> classesToEnhance, File directory) {
|
||||
this.classesToEnhance = classesToEnhance;
|
||||
this.dumpResult = new HashMap<Class<?>, File>();
|
||||
this.arthasLogHome = new File(LogUtil.LOGGER_FILE).getParentFile();
|
||||
this.arthasLogHome = new File(LogUtil.LOGS_ARTHAS_DIR);
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.File;
|
||||
|
||||
import com.taobao.arthas.core.view.Ansi;
|
||||
|
||||
import static com.taobao.arthas.core.util.LogUtil.LOGS_DIR;
|
||||
|
||||
/**
|
||||
* @author ralf0131 2016-12-28 16:20.
|
||||
*/
|
||||
@@ -50,6 +52,6 @@ public interface Constants {
|
||||
/**
|
||||
* 缓存目录
|
||||
*/
|
||||
String CACHE_ROOT = System.getProperty("user.home") + File.separator + "logs" + File.separator + "arthas-cache";
|
||||
String CACHE_ROOT = LOGS_DIR + File.separator + "arthas-cache";
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.taobao.middleware.logger.LoggerFactory;
|
||||
import com.taobao.middleware.logger.support.LogLog;
|
||||
import com.taobao.middleware.logger.support.LoggerHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Arthas日志
|
||||
* Created by vlinux on 15/3/8.
|
||||
@@ -29,9 +31,22 @@ public class LogUtil {
|
||||
*/
|
||||
private static final Logger termdLogger;
|
||||
|
||||
public static final String LOGGER_FILE = LoggerHelper.getLogFile("arthas", "arthas.log");
|
||||
public static final String LOGGER_FILE;
|
||||
|
||||
/**
|
||||
* default value is ~/logs
|
||||
*/
|
||||
public static String LOGS_DIR;
|
||||
|
||||
/**
|
||||
* default value is ~/logs/arthas
|
||||
*/
|
||||
public static String LOGS_ARTHAS_DIR;
|
||||
|
||||
static {
|
||||
detectArthasLogDirectory();
|
||||
LOGGER_FILE = LoggerHelper.getLogFile("arthas", "arthas.log");
|
||||
|
||||
LogLog.setQuietMode(true);
|
||||
|
||||
LoggerHelper.setPattern("arthas-cache", "%d{yyyy-MM-dd HH:mm:ss.SSS}%n%m%n");
|
||||
@@ -58,6 +73,38 @@ public class LogUtil {
|
||||
termdLogger.setAdditivity(false);
|
||||
}
|
||||
|
||||
private static void detectArthasLogDirectory() {
|
||||
String dpath = System.getProperty("JM.LOG.PATH");
|
||||
if (StringUtils.isEmpty(dpath)) {
|
||||
File logDirectory = new File(System.getProperty("user.home") + File.separator + "logs" + File.separator);
|
||||
try {
|
||||
// when user is nobody mkdir will fail. #572
|
||||
logDirectory.mkdirs();
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
if (!logDirectory.exists()) {
|
||||
// try to set a temp directory
|
||||
logDirectory = new File(System.getProperty("java.io.tmpdir") + File.separator + "logs" + File.separator);
|
||||
try {
|
||||
logDirectory.mkdirs();
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (logDirectory.exists()) {
|
||||
LOGS_DIR = logDirectory.getAbsolutePath();
|
||||
System.setProperty("JM.LOG.PATH", logDirectory.getAbsolutePath());
|
||||
}
|
||||
} else {
|
||||
LOGS_DIR = dpath;
|
||||
}
|
||||
if (StringUtils.isEmpty(LOGS_DIR)) {
|
||||
LOGS_DIR = "logs";
|
||||
}
|
||||
LOGS_ARTHAS_DIR = LOGS_DIR + File.separator + "arthas";
|
||||
}
|
||||
|
||||
public static Logger getArthasLogger() {
|
||||
return arthasLogger;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user