日志优化
This commit is contained in:
@@ -19,7 +19,7 @@ java.util.logging.FileHandler.pattern = ${APP_HOME}/logs-%tY%tm/log-%tY%tm%td.lo
|
||||
#java.util.logging.FileHandler.unusual \u5c5e\u6027\u8868\u793a\u5c06 WARNING\u3001SEVERE \u7ea7\u522b\u7684\u65e5\u5fd7\u590d\u5236\u5199\u5165\u5355\u72ec\u7684\u6587\u4ef6\u4e2d
|
||||
java.util.logging.FileHandler.unusual = ${APP_HOME}/logs-%tY%tm/log-warnerr-%tY%tm%td.log
|
||||
#\u9700\u8981\u5c4f\u853d\u6d88\u606f\u5185\u5bb9\u7684\u6b63\u5219\u8868\u8fbe\u5f0f
|
||||
java.util.logging.FileHandler.denyreg =
|
||||
java.util.logging.FileHandler.denyregx =
|
||||
java.util.logging.FileHandler.append = true
|
||||
|
||||
#java.util.logging.ConsoleHandler.level = FINE
|
||||
|
||||
@@ -697,7 +697,7 @@ public final class Application {
|
||||
ps.load(in);
|
||||
in.close();
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.log(Level.FINE, "load properties(" + dfload + ") size = " + ps.size());
|
||||
logger.log(Level.FINE, "Load properties(" + dfload + ") size = " + ps.size());
|
||||
}
|
||||
ps.forEach((x, y) -> { //load中的配置项除了redkale.cachesource.和redkale.datasource.开头,不应该有其他redkale.开头配置项
|
||||
if (!x.toString().startsWith("redkale.")) {
|
||||
@@ -707,7 +707,7 @@ public final class Application {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "load properties(" + dfload + ") error", e);
|
||||
logger.log(Level.WARNING, "Load properties(" + dfload + ") error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1089,7 +1089,7 @@ public final class Application {
|
||||
rf.register(resourceName, java.net.http.HttpClient.class, httpClient);
|
||||
return httpClient;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "[" + Thread.currentThread().getName() + "] java.net.http.HttpClient inject error", e);
|
||||
logger.log(Level.SEVERE, "java.net.http.HttpClient inject error", e);
|
||||
return null;
|
||||
}
|
||||
}, java.net.http.HttpClient.class);
|
||||
@@ -1103,7 +1103,7 @@ public final class Application {
|
||||
rf.register(resourceName, HttpSimpleClient.class, httpClient);
|
||||
return httpClient;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "[" + Thread.currentThread().getName() + "] HttpClient inject error", e);
|
||||
logger.log(Level.SEVERE, "HttpClient inject error", e);
|
||||
return null;
|
||||
}
|
||||
}, HttpSimpleClient.class);
|
||||
@@ -1153,7 +1153,7 @@ public final class Application {
|
||||
rf.register(resourceName, HttpMessageClient.class, messageClient);
|
||||
return messageClient;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "[" + Thread.currentThread().getName() + "] HttpMessageClient inject error", e);
|
||||
logger.log(Level.SEVERE, "HttpMessageClient inject error", e);
|
||||
return null;
|
||||
}
|
||||
}, HttpMessageClient.class);
|
||||
@@ -1195,14 +1195,14 @@ public final class Application {
|
||||
cacheSources.add(source);
|
||||
resourceFactory.register(sourceName, CacheSource.class, source);
|
||||
if (!compileMode && source instanceof Service) ((Service) source).init(sourceConf);
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load CacheSource resourceName = " + sourceName + ", source = " + source + " in " + (System.currentTimeMillis() - st) + " ms");
|
||||
logger.info("Load CacheSource resourceName = " + sourceName + ", source = " + source + " in " + (System.currentTimeMillis() - st) + " ms");
|
||||
return source;
|
||||
}
|
||||
try {
|
||||
CacheSource source = AbstractCacheSource.createCacheSource(serverClassLoader, resourceFactory, sourceConf, sourceName, compileMode);
|
||||
cacheSources.add(source);
|
||||
resourceFactory.register(sourceName, source);
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load CacheSource resourceName = " + sourceName + ", source = " + source + " in " + (System.currentTimeMillis() - st) + " ms");
|
||||
logger.info("Load CacheSource resourceName = " + sourceName + ", source = " + source + " in " + (System.currentTimeMillis() - st) + " ms");
|
||||
return source;
|
||||
} catch (RuntimeException ex) {
|
||||
throw ex;
|
||||
@@ -1225,7 +1225,7 @@ public final class Application {
|
||||
}
|
||||
dataSources.add(source);
|
||||
resourceFactory.register(sourceName, DataSource.class, source);
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load DataSource resourceName = " + sourceName + ", source = " + source);
|
||||
logger.info("Load DataSource resourceName = " + sourceName + ", source = " + source);
|
||||
return source;
|
||||
}
|
||||
try {
|
||||
@@ -1236,7 +1236,7 @@ public final class Application {
|
||||
} else {
|
||||
resourceFactory.register(sourceName, source);
|
||||
}
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load DataSource resourceName = " + sourceName + ", source = " + source);
|
||||
logger.info("Load DataSource resourceName = " + sourceName + ", source = " + source);
|
||||
return source;
|
||||
} catch (RuntimeException ex) {
|
||||
throw ex;
|
||||
@@ -1313,7 +1313,7 @@ public final class Application {
|
||||
logger.info(application.getClass().getSimpleName() + " shutdown in " + e + " ms");
|
||||
channel.close();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.INFO, "shutdown fail", ex);
|
||||
logger.log(Level.INFO, "Shutdown fail", ex);
|
||||
sendUdpData(channel, address, buffer, "shutdown fail".getBytes(StandardCharsets.UTF_8));
|
||||
} finally {
|
||||
loop = false;
|
||||
@@ -1502,7 +1502,7 @@ public final class Application {
|
||||
String ms = String.valueOf(intms);
|
||||
int repeat = ms.length() > 7 ? 0 : (7 - ms.length()) / 2;
|
||||
logger.info(colorMessage(logger, 36, 1, "-".repeat(repeat) + "------------------------ Redkale started in " + ms + " ms " + (ms.length() / 2 == 0 ? " " : "") + "-".repeat(repeat) + "------------------------") + "\r\n");
|
||||
LoggingBaseHandler.traceflag = true;
|
||||
LoggingBaseHandler.traceFlag = true;
|
||||
|
||||
for (ApplicationListener listener : this.listeners) {
|
||||
listener.postStart(this);
|
||||
@@ -1531,7 +1531,7 @@ public final class Application {
|
||||
long e = System.currentTimeMillis() - s;
|
||||
logger.info(Application.this.getClass().getSimpleName() + " shutdown in " + e + " ms");
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.INFO, "shutdown fail", ex);
|
||||
logger.log(Level.INFO, "Shutdown fail", ex);
|
||||
} finally {
|
||||
shutdownLatch.countDown();
|
||||
}
|
||||
@@ -1953,9 +1953,9 @@ public final class Application {
|
||||
Level logLevel = Level.parse(loggingChangedProps.getProperty(".level"));
|
||||
Logger.getGlobal().setLevel(logLevel);
|
||||
this.loggingProperties.putAll(loggingChangedProps);
|
||||
logger.log(Level.INFO, "reconfig logging level to " + logLevel);
|
||||
logger.log(Level.INFO, "Reconfig logging level to " + logLevel);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "reconfig logging level error, new level is " + loggingChangedProps.getProperty(".level"));
|
||||
logger.log(Level.WARNING, "Reconfig logging level error, new level is " + loggingChangedProps.getProperty(".level"));
|
||||
}
|
||||
} else {
|
||||
Properties newLogProps = new Properties();
|
||||
@@ -1963,7 +1963,7 @@ public final class Application {
|
||||
newLogProps.putAll(loggingChangedProps);
|
||||
loggingRemovedKeys.forEach(k -> newLogProps.remove(k));
|
||||
reconfigLogging(newLogProps);
|
||||
logger.log(Level.INFO, "reconfig logging finished ");
|
||||
logger.log(Level.INFO, "Reconfig logging finished ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -434,8 +434,7 @@ public final class ClassFilter<T> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "[thread=" + Thread.currentThread().getName()
|
||||
+ ", type=" + this.type.getSimpleName() + ", name=" + name + ", groups=" + this.groups + "]";
|
||||
return this.getClass().getSimpleName() + "[type=" + this.type.getSimpleName() + ", name=" + name + ", groups=" + this.groups + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -604,7 +603,7 @@ public final class ClassFilter<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (debug) logger.log(Level.INFO, "scan classes: \r\n{0}", debugstr);
|
||||
//if (debug) logger.log(Level.INFO, "Scan classes: \r\n{0}", debugstr);
|
||||
}
|
||||
|
||||
private static void loadClassFiles(File exclude, File root, List<File> files) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
*/
|
||||
package org.redkale.boot;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.*;
|
||||
import org.redkale.util.Traces;
|
||||
|
||||
@@ -15,21 +16,101 @@ import org.redkale.util.Traces;
|
||||
*/
|
||||
public abstract class LoggingBaseHandler extends Handler {
|
||||
|
||||
static boolean traceflag = false; //防止设置system.property前调用Traces类导致enable提前初始化
|
||||
//public static final String FORMATTER_FORMAT = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL %4$s %2$s%n%5$s%6$s%n";
|
||||
//无threadName、TID
|
||||
public static final String FORMATTER_FORMAT = "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL] %4$s %2$s\r\n%5$s%6$s\r\n";
|
||||
|
||||
//有threadName
|
||||
public static final String FORMATTER_FORMAT2 = "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL] [%7$s] %4$s %2$s\r\n%5$s%6$s\r\n";
|
||||
|
||||
//有threadName、TID
|
||||
public static final String FORMATTER_FORMAT3 = "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL] [%7$s] %8$s %4$s %2$s\r\n%5$s%6$s\r\n";
|
||||
|
||||
/**
|
||||
* 默认的日志时间格式化类
|
||||
* 与SimpleFormatter的区别在于level不使用本地化
|
||||
*
|
||||
*/
|
||||
public static class LoggingFormater extends Formatter {
|
||||
|
||||
@Override
|
||||
public String format(LogRecord log) {
|
||||
if (log.getThrown() == null && log.getMessage() != null && log.getMessage().startsWith("------")) {
|
||||
return formatMessage(log) + "\r\n";
|
||||
}
|
||||
String source;
|
||||
if (log.getSourceClassName() != null) {
|
||||
source = log.getSourceClassName();
|
||||
if (log.getSourceMethodName() != null) {
|
||||
source += " " + log.getSourceMethodName();
|
||||
}
|
||||
} else {
|
||||
source = log.getLoggerName();
|
||||
}
|
||||
String message = formatMessage(log);
|
||||
String throwable = "";
|
||||
if (log.getThrown() != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw) {
|
||||
@Override
|
||||
public void println() {
|
||||
super.print("\r\n");
|
||||
}
|
||||
};
|
||||
pw.println();
|
||||
log.getThrown().printStackTrace(pw);
|
||||
pw.close();
|
||||
throwable = sw.toString();
|
||||
}
|
||||
Object[] params = log.getParameters();
|
||||
if (params != null) {
|
||||
if (params.length == 1) {
|
||||
return String.format(FORMATTER_FORMAT2,
|
||||
log.getInstant().toEpochMilli(),
|
||||
source,
|
||||
log.getLoggerName(),
|
||||
log.getLevel().getName(),
|
||||
message,
|
||||
throwable,
|
||||
params[0]);
|
||||
} else if (params.length == 2) {
|
||||
return String.format(FORMATTER_FORMAT3,
|
||||
log.getInstant().toEpochMilli(),
|
||||
source,
|
||||
log.getLoggerName(),
|
||||
log.getLevel().getName(),
|
||||
message,
|
||||
throwable,
|
||||
params[0],
|
||||
params[1]);
|
||||
}
|
||||
}
|
||||
return String.format(FORMATTER_FORMAT,
|
||||
log.getInstant().toEpochMilli(),
|
||||
source,
|
||||
log.getLoggerName(),
|
||||
log.getLevel().getName(),
|
||||
message,
|
||||
throwable);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean traceFlag = false; //防止设置system.property前调用Traces类导致enable提前初始化
|
||||
|
||||
protected static void fillLogRecord(LogRecord log) {
|
||||
if (traceflag && Traces.enable()) {
|
||||
String traceid = Traces.currTraceid();
|
||||
String traceid = null;
|
||||
if (traceFlag && Traces.enable()) {
|
||||
traceid = Traces.currTraceid();
|
||||
if (traceid == null || traceid.isEmpty()) {
|
||||
traceid = "[TID:N/A] ";
|
||||
} else {
|
||||
traceid = "[TID:" + traceid + "] ";
|
||||
}
|
||||
if (log.getMessage() == null) {
|
||||
log.setMessage(traceid);
|
||||
} else {
|
||||
log.setMessage(traceid + log.getMessage());
|
||||
}
|
||||
}
|
||||
if (traceid == null) {
|
||||
log.setParameters(new String[]{Thread.currentThread().getName()});
|
||||
} else {
|
||||
log.setParameters(new String[]{Thread.currentThread().getName(), traceid});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,13 @@
|
||||
*/
|
||||
package org.redkale.boot;
|
||||
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.Files;
|
||||
import static java.nio.file.StandardCopyOption.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.regex.Pattern;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@@ -28,9 +25,6 @@ import org.redkale.util.*;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
|
||||
//public static final String FORMATTER_FORMAT = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL %4$s %2$s%n%5$s%6$s%n";
|
||||
public static final String FORMATTER_FORMAT = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL %4$s %2$s\r\n%5$s%6$s\r\n";
|
||||
|
||||
/**
|
||||
* SNCP的日志输出Handler
|
||||
*/
|
||||
@@ -54,13 +48,13 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
|
||||
private void configure() {
|
||||
LogManager manager = LogManager.getLogManager();
|
||||
String denyregstr = manager.getProperty(LoggingConsoleHandler.class.getName() + ".denyreg");
|
||||
if (denyregstr == null) {
|
||||
denyregstr = manager.getProperty("java.util.logging.ConsoleHandler.denyreg");
|
||||
String denyregxstr = manager.getProperty(LoggingConsoleHandler.class.getName() + ".denyregx");
|
||||
if (denyregxstr == null) {
|
||||
denyregxstr = manager.getProperty("java.util.logging.ConsoleHandler.denyregx");
|
||||
}
|
||||
try {
|
||||
if (denyregstr != null && !denyregstr.trim().isEmpty()) {
|
||||
this.denyRegx = Pattern.compile(denyregstr);
|
||||
if (denyregxstr != null && !denyregxstr.trim().isEmpty()) {
|
||||
this.denyRegx = Pattern.compile(denyregxstr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@@ -74,52 +68,6 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的日志时间格式化类
|
||||
* 与SimpleFormatter的区别在于level不使用本地化
|
||||
*
|
||||
*/
|
||||
public static class LoggingFormater extends Formatter {
|
||||
|
||||
@Override
|
||||
public String format(LogRecord log) {
|
||||
if (log.getThrown() == null && log.getMessage() != null && log.getMessage().startsWith("------")) {
|
||||
return formatMessage(log) + "\r\n";
|
||||
}
|
||||
String source;
|
||||
if (log.getSourceClassName() != null) {
|
||||
source = log.getSourceClassName();
|
||||
if (log.getSourceMethodName() != null) {
|
||||
source += " " + log.getSourceMethodName();
|
||||
}
|
||||
} else {
|
||||
source = log.getLoggerName();
|
||||
}
|
||||
String message = formatMessage(log);
|
||||
String throwable = "";
|
||||
if (log.getThrown() != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw) {
|
||||
@Override
|
||||
public void println() {
|
||||
super.print("\r\n");
|
||||
}
|
||||
};
|
||||
pw.println();
|
||||
log.getThrown().printStackTrace(pw);
|
||||
pw.close();
|
||||
throwable = sw.toString();
|
||||
}
|
||||
return String.format(FORMATTER_FORMAT,
|
||||
System.currentTimeMillis(),
|
||||
source,
|
||||
log.getLoggerName(),
|
||||
log.getLevel().getName(),
|
||||
message,
|
||||
throwable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initDebugLogConfig() {
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
@@ -131,7 +79,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
ps.println("com.sun.level = INFO");
|
||||
ps.println("javax.level = INFO");
|
||||
ps.println("java.util.logging.ConsoleHandler.level = FINEST");
|
||||
ps.println("java.util.logging.ConsoleHandler.formatter = " + LoggingFileHandler.LoggingFormater.class.getName());
|
||||
ps.println("java.util.logging.ConsoleHandler.formatter = " + LoggingFormater.class.getName());
|
||||
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(out.toByteArray()));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@@ -159,7 +107,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
|
||||
protected boolean append;
|
||||
|
||||
protected Pattern denyreg;
|
||||
protected Pattern denyregx;
|
||||
|
||||
private final AtomicLong loglength = new AtomicLong();
|
||||
|
||||
@@ -367,10 +315,10 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
String denyregstr = manager.getProperty(cname + ".denyreg");
|
||||
String denyregxstr = manager.getProperty(cname + ".denyregx");
|
||||
try {
|
||||
if (denyregstr != null && !denyregstr.trim().isEmpty()) {
|
||||
denyreg = Pattern.compile(denyregstr);
|
||||
if (denyregxstr != null && !denyregxstr.trim().isEmpty()) {
|
||||
denyregx = Pattern.compile(denyregxstr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@@ -379,32 +327,8 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
@Override
|
||||
public void publish(LogRecord log) {
|
||||
if (!isLoggable(log)) return;
|
||||
final String sourceClassName = log.getSourceClassName();
|
||||
if (sourceClassName == null || true) {
|
||||
StackTraceElement[] ses = new Throwable().getStackTrace();
|
||||
for (int i = 2; i < ses.length; i++) {
|
||||
if (ses[i].getClassName().startsWith("java.util.logging")) continue;
|
||||
log.setSourceClassName('[' + Thread.currentThread().getName() + "] " + ses[i].getClassName());
|
||||
log.setSourceMethodName(ses[i].getMethodName());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.setSourceClassName('[' + Thread.currentThread().getName() + "] " + sourceClassName);
|
||||
}
|
||||
if (denyreg != null && denyreg.matcher(log.getMessage()).find()) return;
|
||||
if (traceflag && Traces.enable()) {
|
||||
String traceid = Traces.currTraceid();
|
||||
if (traceid == null || traceid.isEmpty()) {
|
||||
traceid = "[TID:N/A] ";
|
||||
} else {
|
||||
traceid = "[TID:" + traceid + "] ";
|
||||
}
|
||||
if (log.getMessage() == null) {
|
||||
log.setMessage(traceid);
|
||||
} else {
|
||||
log.setMessage(traceid + log.getMessage());
|
||||
}
|
||||
}
|
||||
if (denyregx != null && denyregx.matcher(log.getMessage()).find()) return;
|
||||
fillLogRecord(log);
|
||||
logqueue.offer(log);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,10 +177,10 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
String denyregstr = manager.getProperty(cname + ".denyreg");
|
||||
String denyregxstr = manager.getProperty(cname + ".denyregx");
|
||||
try {
|
||||
if (denyregstr != null && !denyregstr.trim().isEmpty()) {
|
||||
denyRegx = Pattern.compile(denyregstr);
|
||||
if (denyregxstr != null && !denyregxstr.trim().isEmpty()) {
|
||||
denyRegx = Pattern.compile(denyregxstr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@@ -189,8 +189,8 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
@Override
|
||||
public void publish(LogRecord log) {
|
||||
if (!isLoggable(log)) return;
|
||||
final String sourceClassName = log.getSourceClassName();
|
||||
if (sourceClassName == null || true) {
|
||||
if (denyRegx != null && denyRegx.matcher(log.getMessage()).find()) return;
|
||||
if (log.getSourceClassName() != null) {
|
||||
StackTraceElement[] ses = new Throwable().getStackTrace();
|
||||
for (int i = 2; i < ses.length; i++) {
|
||||
if (ses[i].getClassName().startsWith("java.util.logging")) continue;
|
||||
@@ -199,7 +199,6 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (denyRegx != null && denyRegx.matcher(log.getMessage()).find()) return;
|
||||
String rawTag = tagDateFormat == null ? tag : Utility.formatTime(tagDateFormat, -1, log.getInstant().toEpochMilli());
|
||||
fillLogRecord(log);
|
||||
logqueue.offer(new SearchLogRecord(rawTag, log));
|
||||
@@ -265,7 +264,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
this.rawLog = log;
|
||||
this.rawTag = tag;
|
||||
this.threadName = Thread.currentThread().getName();
|
||||
this.traceid = LoggingFileHandler.traceflag ? Traces.currTraceid() : null;
|
||||
this.traceid = LoggingBaseHandler.traceFlag ? Traces.currTraceid() : null;
|
||||
String msg = log.getMessage();
|
||||
if (log.getThrown() != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
@@ -142,7 +142,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
}
|
||||
resourceFactory.inject(resourceName, nodeService, self);
|
||||
field.set(srcObj, nodeService);
|
||||
logger.fine("[" + Thread.currentThread().getName() + "] Load Service " + nodeService);
|
||||
logger.fine("Load Service " + nodeService);
|
||||
return nodeService;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -155,7 +155,6 @@ public class NodeHttpServer extends NodeServer {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void loadHttpFilter(final ClassFilter<? extends Filter> classFilter) throws Exception {
|
||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
List<FilterEntry<? extends Filter>> list = new ArrayList(classFilter.getFilterEntrys());
|
||||
for (FilterEntry<? extends Filter> en : list) {
|
||||
Class<HttpFilter> clazz = (Class<HttpFilter>) en.getType();
|
||||
@@ -165,7 +164,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
resourceFactory.inject(filter, this);
|
||||
DefaultAnyValue filterConf = (DefaultAnyValue) en.getProperty();
|
||||
this.httpServer.addHttpFilter(filter, filterConf);
|
||||
if (sb != null) sb.append(localThreadName).append(" Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
if (sb != null) sb.append("Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
}
|
||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
|
||||
}
|
||||
@@ -181,7 +180,6 @@ public class NodeHttpServer extends NodeServer {
|
||||
if (!prefix0.isEmpty() && prefix0.charAt(prefix0.length() - 1) == '/') prefix0 = prefix0.substring(0, prefix0.length() - 1);
|
||||
if (!prefix0.isEmpty() && prefix0.charAt(0) != '/') prefix0 = '/' + prefix0;
|
||||
final String prefix = prefix0;
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
List<FilterEntry<? extends Servlet>> list = new ArrayList(servletFilter.getFilterEntrys());
|
||||
list.sort((FilterEntry<? extends Servlet> o1, FilterEntry<? extends Servlet> o2) -> { //必须保证WebSocketServlet优先加载, 因为要确保其他的HttpServlet可以注入本地模式的WebSocketNode
|
||||
boolean ws1 = WebSocketServlet.class.isAssignableFrom(o1.getType());
|
||||
@@ -203,7 +201,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
WebServlet ws = clazz.getAnnotation(WebServlet.class);
|
||||
if (ws == null) continue;
|
||||
if (ws.value().length == 0) {
|
||||
logger.log(Level.INFO, "not found @WebServlet.value in " + clazz.getName());
|
||||
logger.log(Level.INFO, "Not found @WebServlet.value in " + clazz.getName());
|
||||
continue;
|
||||
}
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(clazz, clazz.getName());
|
||||
@@ -285,13 +283,13 @@ public class NodeHttpServer extends NodeServer {
|
||||
if (as.getKey().length() > max) max = as.getKey().length();
|
||||
}
|
||||
for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
|
||||
sb.append(localThreadName).append("Load ").append(as.getKey());
|
||||
sb.append("Load ").append(as.getKey());
|
||||
for (int i = 0; i < max - as.getKey().length(); i++) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(" mapping to ").append(Arrays.toString(as.getValue())).append(LINE_SEPARATOR);
|
||||
}
|
||||
sb.append(localThreadName).append("All HttpServlets load in ").append(System.currentTimeMillis() - starts).append(" ms").append(LINE_SEPARATOR);
|
||||
sb.append("All HttpServlets load in ").append(System.currentTimeMillis() - starts).append(" ms").append(LINE_SEPARATOR);
|
||||
}
|
||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString().trim());
|
||||
}
|
||||
@@ -306,7 +304,6 @@ public class NodeHttpServer extends NodeServer {
|
||||
if (!prefix0.isEmpty() && prefix0.charAt(prefix0.length() - 1) == '/') prefix0 = prefix0.substring(0, prefix0.length() - 1);
|
||||
if (!prefix0.isEmpty() && prefix0.charAt(0) != '/') prefix0 = '/' + prefix0;
|
||||
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
String mqname = restConf.getValue("mq");
|
||||
MessageAgent agent0 = null;
|
||||
if (mqname != null) {
|
||||
@@ -361,7 +358,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
resourceFactory.inject(servlet, NodeHttpServer.this);
|
||||
dynServletMap.put(service, servlet);
|
||||
if (messageAgent != null) messageAgent.putService(this, service, servlet);
|
||||
//if (finest) logger.finest(localThreadName + " Create RestServlet(resource.name='" + name + "') = " + servlet);
|
||||
//if (finest) logger.finest("Create RestServlet(resource.name='" + name + "') = " + servlet);
|
||||
if (rests != null) {
|
||||
String[] mappings = servlet.getClass().getAnnotation(WebServlet.class).value();
|
||||
for (int i = 0; i < mappings.length; i++) {
|
||||
@@ -420,7 +417,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
if (ws != null && !ws.repair()) prefix2 = "";
|
||||
resourceFactory.inject(servlet, NodeHttpServer.this);
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.finest(localThreadName + " " + stype.getName() + " create a RestWebSocketServlet");
|
||||
logger.finest(stype.getName() + " create a RestWebSocketServlet");
|
||||
}
|
||||
if (webss != null) {
|
||||
String[] mappings = servlet.getClass().getAnnotation(WebServlet.class).value();
|
||||
|
||||
@@ -271,10 +271,10 @@ public abstract class NodeServer {
|
||||
field.set(srcObj, service);
|
||||
rf.inject(resourceName, service, self); // 给其可能包含@Resource的字段赋值;
|
||||
if (!application.isCompileMode()) service.init(null);
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load Service(@Local @AutoLoad service = " + resServiceType.getSimpleName() + ", resourceName = '" + resourceName + "')");
|
||||
logger.info("Load Service(@Local @AutoLoad service = " + resServiceType.getSimpleName() + ", resourceName = '" + resourceName + "')");
|
||||
return service;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "[" + Thread.currentThread().getName() + "] Load @Local @AutoLoad(false) Service inject " + resServiceType + " to " + srcObj + " error", e);
|
||||
logger.log(Level.SEVERE, "Load @Local @AutoLoad(false) Service inject " + resServiceType + " to " + srcObj + " error", e);
|
||||
return null;
|
||||
}
|
||||
}, Service.class);
|
||||
@@ -288,7 +288,7 @@ public abstract class NodeServer {
|
||||
field.set(srcObj, source);
|
||||
return source;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "[" + Thread.currentThread().getName() + "] DataSource inject to " + srcObj + " error", e);
|
||||
logger.log(Level.SEVERE, "DataSource inject to " + srcObj + " error", e);
|
||||
return null;
|
||||
}
|
||||
}, DataSource.class);
|
||||
@@ -317,7 +317,7 @@ public abstract class NodeServer {
|
||||
sncpServer.getSncpServer().addSncpServlet((Service) source);
|
||||
}
|
||||
}
|
||||
logger.info("[" + Thread.currentThread().getName() + "] Load CacheSource (type = " + (source == null ? null : source.getClass().getSimpleName()) + ", resourceName = '" + resourceName + "')");
|
||||
logger.info("Load CacheSource (type = " + (source == null ? null : source.getClass().getSimpleName()) + ", resourceName = '" + resourceName + "')");
|
||||
return source;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
@@ -390,7 +390,6 @@ public abstract class NodeServer {
|
||||
protected void loadService(ClassFilter<? extends Service> serviceFilter, ClassFilter otherFilter) throws Exception {
|
||||
if (serviceFilter == null) return;
|
||||
final long starts = System.currentTimeMillis();
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
final Set<FilterEntry<? extends Service>> entrys = (Set) serviceFilter.getAllFilterEntrys();
|
||||
ResourceFactory regFactory = isSNCP() ? application.getResourceFactory() : resourceFactory;
|
||||
final ResourceFactory appResourceFactory = application.getResourceFactory();
|
||||
@@ -497,7 +496,7 @@ public abstract class NodeServer {
|
||||
|
||||
if (sb != null) {
|
||||
remoteServices.forEach(y -> {
|
||||
sb.append(localThreadName).append(Sncp.toSimpleString(y, maxNameLength, maxTypeLength)).append(" load and inject").append(LINE_SEPARATOR);
|
||||
sb.append(Sncp.toSimpleString(y, maxNameLength, maxTypeLength)).append(" load and inject").append(LINE_SEPARATOR);
|
||||
});
|
||||
}
|
||||
if (isSNCP() && !sncpRemoteAgents.isEmpty()) {
|
||||
@@ -528,7 +527,7 @@ public abstract class NodeServer {
|
||||
if (application.isCompileMode()) {
|
||||
localServices.stream().forEach(y -> {
|
||||
String serstr = Sncp.toSimpleString(y, maxNameLength, maxTypeLength);
|
||||
if (slist != null) slist.add(new StringBuilder().append(localThreadName).append(serstr).append(" load").append(LINE_SEPARATOR).toString());
|
||||
if (slist != null) slist.add(new StringBuilder().append(serstr).append(" load").append(LINE_SEPARATOR).toString());
|
||||
});
|
||||
} else {
|
||||
localServices.stream().forEach(y -> {
|
||||
@@ -536,7 +535,7 @@ public abstract class NodeServer {
|
||||
y.init(Sncp.getConf(y));
|
||||
long e = System.currentTimeMillis() - s;
|
||||
String serstr = Sncp.toSimpleString(y, maxNameLength, maxTypeLength);
|
||||
if (slist != null) slist.add(new StringBuilder().append(localThreadName).append(serstr).append(" load and init in ").append(e < 10 ? " " : (e < 100 ? " " : "")).append(e).append(" ms").append(LINE_SEPARATOR).toString());
|
||||
if (slist != null) slist.add(new StringBuilder().append(serstr).append(" load and init in ").append(e < 10 ? " " : (e < 100 ? " " : "")).append(e).append(" ms").append(LINE_SEPARATOR).toString());
|
||||
});
|
||||
}
|
||||
if (slist != null && sb != null) {
|
||||
@@ -544,9 +543,9 @@ public abstract class NodeServer {
|
||||
for (String s : wlist) {
|
||||
sb.append(s);
|
||||
}
|
||||
sb.append(localThreadName).append("All " + localServices.size() + " Services load in ").append(System.currentTimeMillis() - starts).append(" ms");
|
||||
sb.append("All " + localServices.size() + " Services load in ").append(System.currentTimeMillis() - starts).append(" ms");
|
||||
}
|
||||
if (sb != null && preinite > 10) sb.append(localThreadName).append(ClusterAgent.class.getSimpleName()).append(" register in ").append(preinite).append(" ms" + LINE_SEPARATOR);
|
||||
if (sb != null && preinite > 10) sb.append(ClusterAgent.class.getSimpleName()).append(" register in ").append(preinite).append(" ms" + LINE_SEPARATOR);
|
||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -64,11 +64,10 @@ public class NodeSncpServer extends NodeServer {
|
||||
//-------------------------------------------------------------------
|
||||
if (sncpServer == null) return; //调试时server才可能为null
|
||||
final StringBuilder sb = logger.isLoggable(Level.FINE) ? new StringBuilder() : null;
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
List<SncpServlet> servlets = sncpServer.getSncpServlets();
|
||||
Collections.sort(servlets);
|
||||
for (SncpServlet en : servlets) {
|
||||
if (sb != null) sb.append(localThreadName).append(" Load ").append(en).append(LINE_SEPARATOR);
|
||||
if (sb != null) sb.append("Load ").append(en).append(LINE_SEPARATOR);
|
||||
}
|
||||
if (sb != null && sb.length() > 0) logger.log(Level.FINE, sb.toString());
|
||||
}
|
||||
@@ -90,7 +89,6 @@ public class NodeSncpServer extends NodeServer {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void loadSncpFilter(final AnyValue servletsConf, final ClassFilter<? extends Filter> classFilter) throws Exception {
|
||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||
final String localThreadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
List<FilterEntry<? extends Filter>> list = new ArrayList(classFilter.getFilterEntrys());
|
||||
for (FilterEntry<? extends Filter> en : list) {
|
||||
Class<SncpFilter> clazz = (Class<SncpFilter>) en.getType();
|
||||
@@ -100,7 +98,7 @@ public class NodeSncpServer extends NodeServer {
|
||||
resourceFactory.inject(filter, this);
|
||||
DefaultAnyValue filterConf = (DefaultAnyValue) en.getProperty();
|
||||
this.sncpServer.addSncpFilter(filter, filterConf);
|
||||
if (sb != null) sb.append(localThreadName).append(" Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
if (sb != null) sb.append("Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
}
|
||||
if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@ import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.logging.*;
|
||||
import javax.net.ssl.*;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.net.Filter;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -35,7 +36,6 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
//@Deprecated //@deprecated 2.3.0 使用RESNAME_APP_EXECUTOR
|
||||
//public static final String RESNAME_SERVER_EXECUTOR2 = "SERVER_EXECUTOR";
|
||||
//public static final String RESNAME_SERVER_RESFACTORY = "SERVER_RESFACTORY";
|
||||
|
||||
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
|
||||
//-------------------------------------------------------------
|
||||
@@ -155,9 +155,8 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
//SSL模式下, size必须大于 5+16+16384+256+48+(isDTLS?0:16384) = 16k*1/2+325 = 16709/33093 见: sun.security.ssl.SSLRecord.maxLargeRecordSize
|
||||
int maxLen = dtls ? 16709 : 33093;
|
||||
if (maxLen > this.bufferCapacity) {
|
||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
int newLen = dtls ? (17 * 1024) : (33 * 1024); //取个1024的整倍数
|
||||
logger.info(threadName + this.getClass().getSimpleName() + " change bufferCapacity " + this.bufferCapacity + " to " + newLen + " for SSL size " + maxLen);
|
||||
logger.info(this.getClass().getSimpleName() + " change bufferCapacity " + this.bufferCapacity + " to " + newLen + " for SSL size " + maxLen);
|
||||
this.bufferCapacity = newLen;
|
||||
}
|
||||
}
|
||||
@@ -283,9 +282,8 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
this.serverChannel.open(config);
|
||||
serverChannel.bind(address, backlog);
|
||||
serverChannel.accept(application, this);
|
||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
postStart();
|
||||
logger.info(threadName + this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol)) + " listen: " + (address.getHostString() + ":" + address.getPort())
|
||||
logger.info(this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol)) + " listen: " + (address.getHostString() + ":" + address.getPort())
|
||||
+ ", cpu: " + Utility.cpus() + ", responsePoolSize: " + responsePoolSize + ", bufferPoolSize: " + bufferPoolSize
|
||||
+ ", bufferCapacity: " + formatLenth(bufferCapacity) + ", maxbody: " + formatLenth(context.maxbody)
|
||||
+ ", started in " + (System.currentTimeMillis() - context.getServerStartTime()) + " ms\r\n");
|
||||
@@ -315,8 +313,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
}
|
||||
this.address = context.address;
|
||||
this.serverChannel = newServerChannel;
|
||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||
logger.info(threadName + this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol))
|
||||
logger.info(this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol))
|
||||
+ " change address listen: " + address + ", started in " + (System.currentTimeMillis() - s) + " ms");
|
||||
if (oldServerChannel != null) {
|
||||
new Thread() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.function.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.util.*;
|
||||
@@ -209,7 +209,7 @@ public abstract class ClientConnection<R extends ClientRequest, P> implements Co
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
client.logger.log(Level.INFO, "complete result error, request: " + respFuture.request, t);
|
||||
client.logger.log(Level.INFO, "Complete result error, request: " + respFuture.request, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
*/
|
||||
package org.redkale.net.sncp;
|
||||
|
||||
import org.redkale.annotation.ConstructorParameters;
|
||||
import org.redkale.asm.MethodDebugVisitor;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.*;
|
||||
import org.redkale.annotation.ConstructorParameters;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
import org.redkale.asm.*;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
import org.redkale.convert.bson.*;
|
||||
@@ -295,7 +294,7 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
response.getContext().getLogger().log(Level.INFO, "sncp execute error(" + request + ")", exc);
|
||||
response.getContext().getLogger().log(Level.INFO, "Sncp execute error(" + request + ")", exc);
|
||||
response.finish(SncpResponse.RETCODE_THROWEXCEPTION, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ package org.redkale.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
@@ -229,7 +229,7 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
// if (debug) {
|
||||
// for (T t : queue) {
|
||||
// if (t == e) {
|
||||
// logger.log(Level.WARNING, "[" + Thread.currentThread().getName() + "] repeat offer the same object(" + e + ")", new Exception());
|
||||
// logger.log(Level.WARNING, "repeat offer the same object(" + e + ")", new Exception());
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user