/** * Log a message at the TRACE level. * * @param msg the message string to be logged */ publicstaticvoidtrace(String msg) { log.trace(msg); }
/** * Log a message at the TRACE level according to the specified format * and argument. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the TRACE level. </p> * * @param format the format string * @param arg the argument */ publicstaticvoidtrace(String format, Object arg) { log.trace(format, arg); }
/** * Log a message at the TRACE level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the TRACE level. </p> * * @param format the format string * @param arg1 the first argument * @param arg2 the second argument */ publicstaticvoidtrace(String format, Object arg1, Object arg2) { log.trace(format, arg1, arg2); }
/** * Log a message at the TRACE level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous string concatenation when the logger * is disabled for the TRACE level. However, this variant incurs the hidden * (and relatively small) cost of creating an <code>Object[]</code> before invoking the method, * even if this logger is disabled for TRACE. The variants taking {@link #trace(String, Object) one} and * {@link #trace(String, Object, Object) two} arguments exist solely in order to avoid this hidden cost.</p> * * @param format the format string * @param arguments a list of 3 or more arguments */ publicstaticvoidtrace(String format, Object... arguments) { log.trace(format, arguments); }
/** * Log an exception (throwable) at the TRACE level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ publicstaticvoidtrace(String msg, Throwable t) { log.trace(msg, t); }
/** * Log a message at the DEBUG level. * * @param msg the message string to be logged */ publicstaticvoiddebug(String msg) { }
/** * Log a message at the DEBUG level according to the specified format * and argument. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the DEBUG level. </p> * * @param format the format string * @param arg the argument */ publicstaticvoiddebug(String format, Object arg) { }
/** * Log a message at the DEBUG level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the DEBUG level. </p> * * @param format the format string * @param arg1 the first argument * @param arg2 the second argument */ publicstaticvoiddebug(String format, Object arg1, Object arg2) { }
/** * Log a message at the DEBUG level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous string concatenation when the logger * is disabled for the DEBUG level. However, this variant incurs the hidden * (and relatively small) cost of creating an <code>Object[]</code> before invoking the method, * even if this logger is disabled for DEBUG. The variants taking * {@link #debug(String, Object) one} and {@link #debug(String, Object, Object) two} * arguments exist solely in order to avoid this hidden cost.</p> * * @param format the format string * @param arguments a list of 3 or more arguments */ publicstaticvoiddebug(String format, Object... arguments) { }
/** * Log an exception (throwable) at the DEBUG level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ publicstaticvoiddebug(String msg, Throwable t) { }
/** * Log a message at the INFO level. * * @param msg the message string to be logged */ publicstaticvoidinfo(String msg) { }
/** * Log a message at the INFO level according to the specified format * and argument. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the INFO level. </p> * * @param format the format string * @param arg the argument */ publicstaticvoidinfo(String format, Object arg) { }
/** * Log a message at the INFO level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the INFO level. </p> * * @param format the format string * @param arg1 the first argument * @param arg2 the second argument */ publicstaticvoidinfo(String format, Object arg1, Object arg2) { }
/** * Log a message at the INFO level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous string concatenation when the logger * is disabled for the INFO level. However, this variant incurs the hidden * (and relatively small) cost of creating an <code>Object[]</code> before invoking the method, * even if this logger is disabled for INFO. The variants taking * {@link #info(String, Object) one} and {@link #info(String, Object, Object) two} * arguments exist solely in order to avoid this hidden cost.</p> * * @param format the format string * @param arguments a list of 3 or more arguments */ publicstaticvoidinfo(String format, Object... arguments) { }
/** * Log an exception (throwable) at the INFO level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ publicstaticvoidinfo(String msg, Throwable t) { } /** * Log a message at the WARN level. * * @param msg the message string to be logged */ publicstaticvoidwarn(String msg) { }
/** * Log a message at the WARN level according to the specified format * and argument. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the WARN level. </p> * * @param format the format string * @param arg the argument */ publicstaticvoidwarn(String format, Object arg) { }
/** * Log a message at the WARN level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous string concatenation when the logger * is disabled for the WARN level. However, this variant incurs the hidden * (and relatively small) cost of creating an <code>Object[]</code> before invoking the method, * even if this logger is disabled for WARN. The variants taking * {@link #warn(String, Object) one} and {@link #warn(String, Object, Object) two} * arguments exist solely in order to avoid this hidden cost.</p> * * @param format the format string * @param arguments a list of 3 or more arguments */ publicstaticvoidwarn(String format, Object... arguments) { }
/** * Log a message at the WARN level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the WARN level. </p> * * @param format the format string * @param arg1 the first argument * @param arg2 the second argument */ publicstaticvoidwarn(String format, Object arg1, Object arg2) { }
/** * Log an exception (throwable) at the WARN level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ publicstaticvoidwarn(String msg, Throwable t) { }
/** * Log a message at the ERROR level. * * @param msg the message string to be logged */ publicstaticvoiderror(String msg) { }
/** * Log a message at the ERROR level according to the specified format * and argument. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the ERROR level. </p> * * @param format the format string * @param arg the argument */ publicstaticvoiderror(String format, Object arg) { }
/** * Log a message at the ERROR level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous object creation when the logger * is disabled for the ERROR level. </p> * * @param format the format string * @param arg1 the first argument * @param arg2 the second argument */ publicstaticvoiderror(String format, Object arg1, Object arg2) { }
/** * Log a message at the ERROR level according to the specified format * and arguments. * <p/> * <p>This form avoids superfluous string concatenation when the logger * is disabled for the ERROR level. However, this variant incurs the hidden * (and relatively small) cost of creating an <code>Object[]</code> before invoking the method, * even if this logger is disabled for ERROR. The variants taking * {@link #error(String, Object) one} and {@link #error(String, Object, Object) two} * arguments exist solely in order to avoid this hidden cost.</p> * * @param format the format string * @param arguments a list of 3 or more arguments */ publicstaticvoiderror(String format, Object... arguments) { }
/** * Log an exception (throwable) at the ERROR level with an * accompanying message. * * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ publicstaticvoiderror(String msg, Throwable t) { }
/** * @param method 方法名 * @param args * @param result * @param thrown */ @SuppressWarnings("rawtypes") @Advice.OnMethodExit(onThrowable = Throwable.class) publicstaticvoidexit(@Advice.Origin Method method, @Advice.AllArguments Object[] args, @Advice.Return Object result, @Advice.Thrown Throwable thrown) { AgentUtil.debug("method is [{}]", method); finalArrayNodearrayNode= AgentJacksonUtil.createArrayNode(); for (Object arg : args) { arrayNode.add(AgentJacksonUtil.toJson(arg)); } finalObjectNodeobjectNode= AgentJacksonUtil.createObjectNode(); objectNode.set("args", arrayNode); ResponseEntityresponseEntity= (ResponseEntity) result; AgentUtil.info("status code is [{}] args is [{}] result is [{}]", responseEntity.getStatusCode(), objectNode, responseEntity.getBody()); }
}
curl命令调用查看效果
1 2
2020-12-31,17:52:01,528+08:00(6121):INFO{}[http-nio-8080-exec-1#39]com.github.hezhangjian.demo.agent.util.AgentUtil.info(AgentUtil.java:167)-->[com.github.hezhangjian.demo.agent.test.controller.TestController createJob] 2020-12-31,17:52:01,544+08:00(6137):INFO{}[http-nio-8080-exec-1#39]com.github.hezhangjian.demo.agent.util.AgentUtil.info(AgentUtil.java:200)-->status code is [201 CREATED] args is [{"args":["\"111\"","{\"description\":\"description\",\"document\":\"document\"}"]}] result is [CreateJobRespDto(description=null, jobArn=null, jobId=null)]
public static void test1() { int size = 10000; FastThreadLocal<String> tls[] = new FastThreadLocal[size]; for (int i = 0; i < size; i++) { tls[i] = new FastThreadLocal<String>(); } new FastThreadLocalThread(new Runnable() {
@Override public void run() { long starTime = System.currentTimeMillis(); for (int i = 0; i < size; i++) { tls[i].set("value" + i); } for (int i = 0; i < size; i++) { for (int k = 0; k < 100000; k++) { tls[i].get(); } } System.out.println(System.currentTimeMillis() - starTime + "ms"); } }).start(); }
// We don't use a fast path as with get() because it is at // least as common to use set() to create new entries as // it is to replace existing ones, in which case, a fast // path would fail more often than not.
private Entry getEntry(ThreadLocal<?> key) { inti= key.threadLocalHashCode & (table.length - 1); Entrye= table[i]; if (e != null && e.get() == key) return e; else return getEntryAfterMiss(key, i, e); }
private Entry getEntryAfterMiss(ThreadLocal<?> key, int i, Entry e) { Entry[] tab = table; intlen= tab.length;
while (e != null) { ThreadLocal<?> k = e.get(); if (k == key) return e; if (k == null) expungeStaleEntry(i); else i = nextIndex(i, len); e = tab[i]; } returnnull; }