提交 1eaa996c 编写于 作者: O o2null

Merge branch 'fix/consoleLog' into 'wrdp'

修正无法执行console命令

See merge request o2oa/o2oa!5632
{
"unitLevelOrderNumberDigits": 10.0,
"pickPersonWithName": true,
"pickIdentityWithName": true,
"pickIdentityWithName": false,
"###unitLevelOrderNumberDigits": "unit中unitLevelOrderNumber扩充位数,\u003c\u003d0不扩充.###",
"###pickPersonWithName": "zhangsan@123@P人员识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过名称进行查找.###",
"###pickIdentityWithName": "zhangsan@456@I身份识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过名称进行查找.###"
......
package com.x.base.core.project.scripting;
import java.util.Objects;
@FunctionalInterface
public interface Consumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(T t);
/**
* Returns a composed {@code Consumer} that performs, in sequence, this
* operation followed by the {@code after} operation. If performing either
* operation throws an exception, it is relayed to the caller of the composed
* operation. If performing this operation throws an exception, the
* {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
* @return a composed {@code Consumer} that performs in sequence this operation
* followed by the {@code after} operation
* @throws NullPointerException if {@code after} is null
*/
default Consumer<T> andThen(Consumer<? super T> after) {
Objects.requireNonNull(after);
return (T t) -> {
accept(t);
after.accept(t);
};
}
}
\ No newline at end of file
......@@ -7,9 +7,11 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.jar.JarFile;
import java.util.stream.Stream;
public class InstrumentationAgent {
private InstrumentationAgent() {
......@@ -39,6 +41,8 @@ public class InstrumentationAgent {
public static final String OS_ARM = "arm";
public static final String OS_MIPS = "mips";
public static final String INSTRUMENTATIONTYPESHADOW = "shadow";
public static void premain(String args, Instrumentation inst) {
String version = System.getProperty("java.vm.specification.version");
if (version.startsWith("1.8")) {
......@@ -55,7 +59,7 @@ public class InstrumentationAgent {
if (Files.exists(base.resolve(DYNAMIC_JARS))) {
load(base, DYNAMIC_JARS);
}
setLog4j2(base);
setLog4j2(base, args);
loadWithCfg(base, STORE_JARS);
loadWithCfg(base, ext());
} catch (Exception e) {
......@@ -127,8 +131,10 @@ public class InstrumentationAgent {
throw new IOException("can not define o2server base directory.");
}
private static void setLog4j2(Path base) {
System.setProperty("log4j.configurationFile", base.resolve("commons").resolve("log4j2.xml").toString());
private static void setLog4j2(Path base, String args) {
if (!Objects.equals(args, INSTRUMENTATIONTYPESHADOW)) {
System.setProperty("log4j.configurationFile", base.resolve("commons").resolve("log4j2.xml").toString());
}
}
}
......@@ -2,13 +2,13 @@ package com.x.server.console;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.StringUtils;
......@@ -26,14 +26,15 @@ public class Shadow {
logger.print("can not find log file,server not running.");
} else {
new Thread(() -> {
try (FileReader fr = new FileReader(logFile); BufferedReader br = new BufferedReader(fr)) {
logger.print("console start, type close to exit console.");
br.skip(logFile.length());
logger.print("console start, type close to exit console.");
try (RandomAccessFile randomFile = new RandomAccessFile(logFile, "r")) {
randomFile.seek(randomFile.length());
String line = null;
while (true) {
if ((line = br.readLine()) != null) {
logger.debug("line:{}.", line);
if ((line = randomFile.readLine()) != null) {
line = new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
System.out.println(line);
continue;
}
sleep();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册