You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to turn off ESAPI logs or change its log level #867
The ESAPI logs will still write to myappLog even though I set level to off. When I print out the Fully Qualified Class Name (FQCN) in the log line, the ESAPI log shows:
If I log down the FQCN and method name (FQCN|methodname), it will show like this:
ERROR : org.owasp.esapi.logging.slf4j.Slf4JLogLevelHandlers$1|IntrusionException.log() - [SECURITY FAILURE Anonymous:@unknown -....
When I set trace level to debug log4j2.xml, I see this log line "TRACE Log4jLoggerFactory.getContext() found anchor class org.owasp.esapi.logging.slf4j.Slf4JLogFactory"
@Override
public Logger getLogger(String moduleName) {
org.slf4j.Logger slf4JLogger = LoggerFactory.getLogger(moduleName);
return new Slf4JLogger(slf4JLogger, LOG_BRIDGE, Logger.ALL);
}
@Override
public Logger getLogger(@SuppressWarnings("rawtypes") Class clazz) {
org.slf4j.Logger slf4JLogger = LoggerFactory.getLogger(clazz);
return new Slf4JLogger(slf4JLogger, LOG_BRIDGE, Logger.ALL);
}
The ESAPI logger is not acting as the originator/owner of the logs. It is working as a decorator to add context to the log being provided from another source. Mute the source, and the logs should follow suit
The LogFactories look up the delegate log based on the module name that is doing the logging, then prefix ESAPI information to that.
I believe if you configure the log appenders for the original classes you'll see the results you're looking for.
@Override
public Logger getLogger(String moduleName) {
org.slf4j.Logger slf4JLogger = LoggerFactory.getLogger(moduleName);
return new Slf4JLogger(slf4JLogger, LOG_BRIDGE, Logger.ALL);
}
@Override
public Logger getLogger(@SuppressWarnings("rawtypes") Class clazz) {
org.slf4j.Logger slf4JLogger = LoggerFactory.getLogger(clazz);
return new Slf4JLogger(slf4JLogger, LOG_BRIDGE, Logger.ALL);
}
The ESAPI logger is not acting as the originator/owner of the logs. It is working as a decorator to add context to the log being provided from another source. Mute the source, and the logs should follow suit
The LogFactories look up the delegate log based on the module name that is doing the logging, then prefix ESAPI information to that.
I believe if you configure the log appenders for the original classes you'll see the results you're looking for.
Change the line <Logger name="org.owasp.esapi" level="off" additivity="false"/>
to target your class/package that is actually calling the SLF4J log methods.
EG: <Logger name="com.myorg.mypackage" level="off" additivity="false"/>
You need to know the true source of the log event.
As a (rough) example:
I have a class com.wizbang.logsample.SimpleLogContent.java
In this class, I'm using ESAPI with the SLF4JLogger configured, and I perform logging invocations.
Thanks for the example. But I still want my class logs to be written, just not the esapi logs. Like IntrusionException, I write my own logging but the logs will come out esapi error log and my own logging
Change the line <Logger name="org.owasp.esapi" level="off" additivity="false"/> to target your class/package that is actually calling the SLF4J log methods. EG: <Logger name="com.myorg.mypackage" level="off" additivity="false"/>
You need to know the true source of the log event.
As a (rough) example: I have a class com.wizbang.logsample.SimpleLogContent.java In this class, I'm using ESAPI with the SLF4JLogger configured, and I perform logging invocations.
You can configure the ESAPI.properties to show/hide certain aspects of the prefix behavior from ESAPI.properties
#===========================================================================
# ESAPI Logging
# Set the application name if these logs are combined with other applications
Logger.ApplicationName=ExampleApplication
# If you use an HTML log viewer that does not properly HTML escape log data, you can set LogEncodingRequired to true
Logger.LogEncodingRequired=false
# Determines whether ESAPI should log the application name. This might be clutter in some single-server/single-app environments.
Logger.LogApplicationName=true
# Determines whether ESAPI should log the server IP and port. This might be clutter in some single-server environments.
Logger.LogServerIP=true
# Determines whether ESAPI should log the user info.
Logger.UserInfo=true
# Determines whether ESAPI should log the session id and client IP.
Logger.ClientInfo=true
# Determines whether ESAPI should log the prefix of [EVENT_TYPE - APPLICATION NAME].
# If all above Logger entries are set to false, as well as LogPrefix, then the output would be the same as if no ESAPI was used
Logger.LogPrefix=true
Toggling these values will trim some of the esapi-specific prefix information from the log behavior.
I write my own logging but the logs will come out esapi error log and my own logging
You could also not duplicate the logs by using your logger or the ESAPI Logger?
If you don't want the ESAPI logs for your classes, then don't use the ESAPI Logger. If you're using ESAPI, then the ESAPI classes will still log (since that's a part of the utility of the library).
If you don't want the utility of the library then I wonder if you should perhaps not be using the library in your project.
Let's move this to the Discussion list (even though it's already closed),
so that others can benefit from the feedback. ESAPI users are more likely
to search for questions like this there rather than in the GitHub issues
because this really isn't a bug or feature enhancement request.
Activity
raine93 commentedon Jan 9, 2025
When I set trace level to debug log4j2.xml, I see this log line "TRACE Log4jLoggerFactory.getContext() found anchor class org.owasp.esapi.logging.slf4j.Slf4JLogFactory"
jeremiahjstacey commentedon Jan 9, 2025
https://github.com/ESAPI/esapi-java-legacy/blob/develop/src/main/java/org/owasp/esapi/logging/slf4j/Slf4JLogFactory.java
The ESAPI logger is not acting as the originator/owner of the logs. It is working as a decorator to add context to the log being provided from another source. Mute the source, and the logs should follow suit
The LogFactories look up the delegate log based on the module name that is doing the logging, then prefix ESAPI information to that.
I believe if you configure the log appenders for the original classes you'll see the results you're looking for.
raine93 commentedon Jan 9, 2025
Can you give an example on how to do that? Like IntrusionException? And turning off all the esapi logs
jeremiahjstacey commentedon Jan 9, 2025
using your syntax from the original post:
Change the line
<Logger name="org.owasp.esapi" level="off" additivity="false"/>to target your class/package that is actually calling the SLF4J log methods.
EG:
<Logger name="com.myorg.mypackage" level="off" additivity="false"/>You need to know the true source of the log event.
As a (rough) example:
I have a class
com.wizbang.logsample.SimpleLogContent.javaIn this class, I'm using ESAPI with the SLF4JLogger configured, and I perform logging invocations.
Logger logger = ESAPI.getLogger(SimpleLogContent.getClass.getName());I decide I no longer want logs from the SimpleLogContent class so I update my log4j2.xml
I should no longer get logs from any class in the package
com.wizbang.logsampleraine93 commentedon Jan 9, 2025
Thanks for the example. But I still want my class logs to be written, just not the esapi logs. Like IntrusionException, I write my own logging but the logs will come out esapi error log and my own logging
jeremiahjstacey commentedon Jan 9, 2025
You can configure the ESAPI.properties to show/hide certain aspects of the prefix behavior from ESAPI.properties
Toggling these values will trim some of the esapi-specific prefix information from the log behavior.
jeremiahjstacey commentedon Jan 9, 2025
You could also not duplicate the logs by using your logger or the ESAPI Logger?
If you don't want the ESAPI logs for your classes, then don't use the ESAPI Logger. If you're using ESAPI, then the ESAPI classes will still log (since that's a part of the utility of the library).
If you don't want the utility of the library then I wonder if you should perhaps not be using the library in your project.
raine93 commentedon Jan 10, 2025
Manage to solve it using custom logger. Thanks for the help
kwwall commentedon Jan 10, 2025