Skip to content

Commit

Permalink
squash with access
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Sep 14, 2024
1 parent 1b576e0 commit c8d0c2b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 76 deletions.
10 changes: 4 additions & 6 deletions psi-probe-core/src/main/java/psiprobe/beans/LogResolverBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
import psiprobe.tools.logging.log4j2.Log4J2LoggerConfigAccessor;
import psiprobe.tools.logging.log4j2.Log4J2LoggerContextAccessor;
import psiprobe.tools.logging.log4j2.Log4J2WebLoggerContextUtilsAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessFactoryAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessLoggerAccessor;
import psiprobe.tools.logging.logback.LogbackFactoryAccessor;
import psiprobe.tools.logging.logback.LogbackLoggerAccessor;
import psiprobe.tools.logging.logback13.Logback13FactoryAccessor;
import psiprobe.tools.logging.logback13.Logback13LoggerAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessFactoryAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessLoggerAccessor;
import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackFactoryAccessor;
import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackLoggerAccessor;
import psiprobe.tools.logging.slf4jlogback13.TomcatSlf4jLogback13FactoryAccessor;
Expand Down Expand Up @@ -454,8 +454,7 @@ private void interrogateClassLoader(ClassLoader cl, Application application,

// check for Logback Access loggers
try {
LogbackAccessFactoryAccessor logbackAccessAccessor =
new LogbackAccessFactoryAccessor(cl);
LogbackAccessFactoryAccessor logbackAccessAccessor = new LogbackAccessFactoryAccessor(cl);
logbackAccessAccessor.setApplication(application);
appenders.addAll(logbackAccessAccessor.getAppenders());
} catch (Exception e) {
Expand All @@ -464,8 +463,7 @@ private void interrogateClassLoader(ClassLoader cl, Application application,

// check for Logback Access 1.3 loggers
try {
LogbackAccessFactoryAccessor logbackAccessAccessor =
new LogbackAccessFactoryAccessor(cl);
LogbackAccessFactoryAccessor logbackAccessAccessor = new LogbackAccessFactoryAccessor(cl);
logbackAccessAccessor.setApplication(application);
appenders.addAll(logbackAccessAccessor.getAppenders());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -13,7 +13,9 @@
import ch.qos.logback.core.OutputStreamAppender;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;

import java.io.File;

import psiprobe.tools.logging.AbstractLogDestination;

/**
Expand Down Expand Up @@ -58,9 +60,9 @@ public String getName() {
}

/**
* Returns the log type, to distinguish logback access appenders from other types like log4j appenders or
* jdk handlers.
*
* Returns the log type, to distinguish logback access appenders from other types like log4j
* appenders or jdk handlers.
*
* @return the log type
*/
@Override
Expand All @@ -70,7 +72,7 @@ public String getLogType() {

/**
* Returns the name of this appender.
*
*
* @return the name of this appender.
*/
@Override
Expand All @@ -81,12 +83,12 @@ public String getIndex() {
/**
* Returns the file that this appender writes to by accessing the {@code file} bean property of
* the appender.
*
*
* <p>
* If no such property exists, we assume the appender to write to stdout or stderr so the output
* will be contained in catalina.out.
* </p>
*
*
* @return the file this appender writes to
*/
@Override
Expand All @@ -113,7 +115,7 @@ public String getEncoding() {

/**
* Gets the level of the associated logger.
*
*
* @return the logger's level
*/
@Override
Expand All @@ -123,11 +125,11 @@ public String getLevel() {

/**
* Returns the valid log level names.
*
*
* <p>
* Note that Logback has no FATAL level.
* </p>
*
*
* @return the valid log level names
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -14,12 +14,14 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.reflect.MethodUtils;

import psiprobe.tools.logging.DefaultAccessor;

/**
* Wraps a Logback logger factory from a given web application class loader.
*
*
* <p>
* All Logback classes are loaded via the given class loader and not via psi-probe's own class
* loader. For this reasons, all methods on Logback objects are invoked via reflection.
Expand All @@ -38,8 +40,8 @@ public class LogbackAccessFactoryAccessor extends DefaultAccessor {
* @throws IllegalAccessException the illegal access exception
* @throws InvocationTargetException the invocation target exception
*/
public LogbackAccessFactoryAccessor(ClassLoader cl) throws ClassNotFoundException,
IllegalAccessException, InvocationTargetException {
public LogbackAccessFactoryAccessor(ClassLoader cl)
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
// Check if Logback Access exists
Class<?> loggerFactoryClass = cl.loadClass("ch.qos.logback.access.spi.AccessContext");
if (loggerFactoryClass == null) {
Expand All @@ -51,7 +53,7 @@ public LogbackAccessFactoryAccessor(ClassLoader cl) throws ClassNotFoundExceptio

/**
* Returns the Logback root logger.
*
*
* @return the root logger
*/
public LogbackAccessLoggerAccessor getRootLogger() {
Expand All @@ -69,8 +71,7 @@ public LogbackAccessLoggerAccessor getRootLogger() {
public LogbackAccessLoggerAccessor getLogger(String name) {
try {
Class<? extends Object> clazz = getTarget().getClass();
Method getLogger = MethodUtils
.getAccessibleMethod(clazz, "getLogger", String.class);
Method getLogger = MethodUtils.getAccessibleMethod(clazz, "getLogger", String.class);

Object logger = getLogger.invoke(getTarget(), name);
if (logger == null) {
Expand All @@ -89,8 +90,9 @@ public LogbackAccessLoggerAccessor getLogger(String name) {

/**
* Returns a list of wrappers for all Logback appenders that have an associated logger.
*
* @return a list of {@link LogbackAccessAppenderAccessor}s representing all appenders that are in use
*
* @return a list of {@link LogbackAccessAppenderAccessor}s representing all appenders that are in
* use
*/
public List<LogbackAccessAppenderAccessor> getAppenders() {
List<LogbackAccessAppenderAccessor> appenders = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -11,11 +11,14 @@
package psiprobe.tools.logging.logbackaccess;

import com.google.common.collect.Iterators;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.reflect.MethodUtils;

import psiprobe.tools.logging.DefaultAccessor;

/**
Expand All @@ -25,14 +28,14 @@ public class LogbackAccessLoggerAccessor extends DefaultAccessor {

/**
* Returns all appenders of this logger.
*
*
* @return a list of {@link LogbackAccessAppenderAccessor}s
*/
public List<LogbackAccessAppenderAccessor> getAppenders() {
List<LogbackAccessAppenderAccessor> appenders = new ArrayList<>();
try {
for (Object appender : Collections.list(Iterators.asEnumeration((Iterator<Object>) MethodUtils
.invokeMethod(getTarget(), "iteratorForAppenders")))) {
for (Object appender : Collections.list(Iterators.asEnumeration(
(Iterator<Object>) MethodUtils.invokeMethod(getTarget(), "iteratorForAppenders")))) {
List<Object> siftedAppenders = getSiftedAppenders(appender);
if (siftedAppenders != null) {
for (Object siftedAppender : siftedAppenders) {
Expand All @@ -43,8 +46,8 @@ public List<LogbackAccessAppenderAccessor> getAppenders() {
}
}
} catch (NoClassDefFoundError e) {
logger.error("{}#getAppenders() failed", getTarget().getClass().getName(), e);
logger.error("To see this logger, upgrade slf4j to 1.7.21+");
logger.error("{}#getAppenders() failed", getTarget().getClass().getName(), e);
logger.error("To see this logger, upgrade slf4j to 1.7.21+");
} catch (Exception e) {
logger.error("{}#getAppenders() failed", getTarget().getClass().getName(), e);
}
Expand All @@ -53,7 +56,7 @@ public List<LogbackAccessAppenderAccessor> getAppenders() {

/**
* Returns the appender of this logger with the given name.
*
*
* @param name the name of the appender to return
* @return the appender with the given name, or null if no such appender exists for this logger
*/
Expand Down Expand Up @@ -104,7 +107,7 @@ public String getName() {

/**
* Gets the log level of this logger.
*
*
* @return the level of this logger
*/
public String getLevel() {
Expand All @@ -119,7 +122,7 @@ public String getLevel() {

/**
* Sets the log level of this logger.
*
*
* @param newLevelStr the name of the new level
*/
public void setLevel(String newLevelStr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed under the GPL License. You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -14,10 +14,10 @@
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;

import psiprobe.tools.logging.AbstractLogDestination;

import java.io.File;

import psiprobe.tools.logging.AbstractLogDestination;

/**
* A wrapper for a Logback appender for a specific logger.
*/
Expand Down Expand Up @@ -60,9 +60,9 @@ public String getName() {
}

/**
* Returns the log type, to distinguish logback access appenders from other types like log4j appenders or
* jdk handlers.
*
* Returns the log type, to distinguish logback access appenders from other types like log4j
* appenders or jdk handlers.
*
* @return the log type
*/
@Override
Expand All @@ -72,7 +72,7 @@ public String getLogType() {

/**
* Returns the name of this appender.
*
*
* @return the name of this appender.
*/
@Override
Expand All @@ -83,12 +83,12 @@ public String getIndex() {
/**
* Returns the file that this appender writes to by accessing the {@code file} bean property of
* the appender.
*
*
* <p>
* If no such property exists, we assume the appender to write to stdout or stderr so the output
* will be contained in catalina.out.
* </p>
*
*
* @return the file this appender writes to
*/
@Override
Expand All @@ -115,7 +115,7 @@ public String getEncoding() {

/**
* Gets the level of the associated logger.
*
*
* @return the logger's level
*/
@Override
Expand All @@ -125,11 +125,11 @@ public String getLevel() {

/**
* Returns the valid log level names.
*
*
* <p>
* Note that Logback has no FATAL level.
* </p>
*
*
* @return the valid log level names
*/
@Override
Expand Down
Loading

0 comments on commit c8d0c2b

Please sign in to comment.