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

Merge branch 'fix/consoleLog' into 'wrdp'

修正无法执行console命令

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