Skip to content

Commit

Permalink
logging wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Nov 12, 2023
1 parent b24f4f7 commit 1a81e26
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
16 changes: 10 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 @@ -54,6 +54,8 @@
import psiprobe.tools.logging.logback13.Logback13LoggerAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessFactoryAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessLoggerAccessor;
import psiprobe.tools.logging.logbackaccess13.LogbackAccess13FactoryAccessor;
import psiprobe.tools.logging.logbackaccess13.LogbackAccess13LoggerAccessor;
import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackFactoryAccessor;
import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackLoggerAccessor;
import psiprobe.tools.logging.slf4jlogback13.TomcatSlf4jLogback13FactoryAccessor;
Expand Down Expand Up @@ -463,9 +465,10 @@ private void interrogateClassLoader(ClassLoader cl, Application application,

// check for Logback Access 1.3 loggers
try {
LogbackAccessFactoryAccessor logbackAccessAccessor = new LogbackAccessFactoryAccessor(cl);
logbackAccessAccessor.setApplication(application);
appenders.addAll(logbackAccessAccessor.getAppenders());
LogbackAccess13FactoryAccessor logbackAccess13Accessor =
new LogbackAccess13FactoryAccessor(cl);
logbackAccess13Accessor.setApplication(application);
appenders.addAll(logbackAccess13Accessor.getAppenders());
} catch (Exception e) {
logger.debug("Could not resolve logback-access 1.3 loggers for '{}'", applicationName, e);
}
Expand Down Expand Up @@ -801,14 +804,15 @@ private LogDestination getLogbackAccess13LogDestination(ClassLoader cl, Applicat
boolean root, String logName, String appenderName) {

try {
LogbackAccessFactoryAccessor manager = new LogbackAccessFactoryAccessor(cl);
LogbackAccess13FactoryAccessor manager = new LogbackAccess13FactoryAccessor(cl);
manager.setApplication(application);
LogbackAccessLoggerAccessor log = root ? manager.getRootLogger() : manager.getLogger(logName);
LogbackAccess13LoggerAccessor log =
root ? manager.getRootLogger() : manager.getLogger(logName);
if (log != null) {
return log.getAppender(appenderName);
}
} catch (Exception e) {
logger.debug("getLogbackAccessLogDestination failed", e);
logger.debug("getLogbackAccess13LogDestination failed", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import psiprobe.tools.logging.logback.LogbackAppenderAccessor;
import psiprobe.tools.logging.logback13.Logback13AppenderAccessor;
import psiprobe.tools.logging.logbackaccess.LogbackAccessAppenderAccessor;
import psiprobe.tools.logging.logbackaccess13.LogbackAccess13AppenderAccessor;
import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackAppenderAccessor;
import psiprobe.tools.logging.slf4jlogback13.TomcatSlf4jLogback13AppenderAccessor;

Expand Down Expand Up @@ -68,6 +69,9 @@ protected ModelAndView handleLogFile(HttpServletRequest request, HttpServletResp
} else if (logDest instanceof LogbackAccessAppenderAccessor) {
LogbackAccessAppenderAccessor accessor = (LogbackAccessAppenderAccessor) logDest;
accessor.getLoggerAccessor().setLevel(level);
} else if (logDest instanceof LogbackAccess13AppenderAccessor) {
LogbackAccess13AppenderAccessor accessor = (LogbackAccess13AppenderAccessor) logDest;
accessor.getLoggerAccessor().setLevel(level);
} else if (logDest instanceof TomcatSlf4jLogbackAppenderAccessor) {
TomcatSlf4jLogbackAppenderAccessor accessor = (TomcatSlf4jLogbackAppenderAccessor) logDest;
accessor.getLoggerAccessor().setLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public String getIndex() {
* <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
*/
Expand All @@ -107,7 +106,6 @@ public String getEncoding() {
if (base.getCharset() != null) {
return base.getCharset().name();
}
return null;
}
}
return null;
Expand All @@ -128,7 +126,6 @@ public String getLevel() {
*
* <p>
* Note that Logback has no FATAL level.
* </p>
*
* @return the valid log level names
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LogbackAccessLoggerAccessor getRootLogger() {
}

/**
* Returns the Logback logger with a given name.
* Returns the Logback Access logger with a given name.
*
* @param name the name
* @return the Logger with the given name
Expand All @@ -89,7 +89,7 @@ public LogbackAccessLoggerAccessor getLogger(String name) {
}

/**
* Returns a list of wrappers for all Logback appenders that have an associated logger.
* Returns a list of wrappers for all Logback Access appenders that have an associated logger.
*
* @return a list of {@link LogbackAccessAppenderAccessor}s representing all appenders that are in
* use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String getName() {
*/
@Override
public String getLogType() {
return "logbackAccess";
return "logbackAccess13";
}

/**
Expand All @@ -87,7 +87,6 @@ public String getIndex() {
* <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
*/
Expand All @@ -107,7 +106,6 @@ public String getEncoding() {
if (base.getCharset() != null) {
return base.getCharset().name();
}
return null;
}
}
return null;
Expand All @@ -128,7 +126,6 @@ public String getLevel() {
*
* <p>
* Note that Logback has no FATAL level.
* </p>
*
* @return the valid log level names
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ public LogbackAccess13LoggerAccessor getRootLogger() {
}

/**
* Returns the Logback logger with a given name.
* Returns the Logback Access logger with a given name.
*
* @param name the name
* @return the Logger with the given name
*/
public LogbackAccess13LoggerAccessor getLogger(String name) {
try {
Class<? extends Object> clazz = getTarget().getClass();
Method getLogger =
MethodUtils.getAccessibleMethod(clazz, "getLogger", new Class[] {String.class});
Method getLogger = MethodUtils.getAccessibleMethod(clazz, "getLogger", String.class);

Object logger = getLogger.invoke(getTarget(), name);
if (logger == null) {
Expand All @@ -99,7 +98,7 @@ public LogbackAccess13LoggerAccessor getLogger(String name) {
}

/**
* Returns a list of wrappers for all Logback appenders that have an associated logger.
* Returns a list of wrappers for all Logback Access appenders that have an associated logger.
*
* @return a list of {@link LogbackAccessAppenderAccessor}s representing all appenders that are in
* use
Expand Down

0 comments on commit 1a81e26

Please sign in to comment.