NCEAS / metacat

Data repository software that helps researchers preserve, share, and discover data
https://knb.ecoinformatics.org/software/metacat
GNU General Public License v2.0
26 stars 12 forks source link

Change logging behavior for NotAuthorized exceptions #1586

Open amoeba opened 2 years ago

amoeba commented 2 years ago

catalina.out has become pretty hard to work with since MetacatUI sends cohorts of isAuthorized calls at Metacat as the user navigates around the site. And every time a client encounters a NotAuthorized exception, we print a full stack trace into catalina.out. For example: On arcticdata.io, NotAuthorized exceptions account for roughly 1,000,000 of 1,167,371 total lines of output.

To make our logs more useful, I suggest we:

I think my change is achieved by:

diff --git src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
index 8f464128..cf6bdb33 100644
--- src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
+++ src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
@@ -53,6 +53,7 @@ import org.dataone.mimemultipart.MultipartRequestResolver;
 import org.dataone.portal.PortalCertificateManager;
 import org.dataone.service.exceptions.BaseException;
 import org.dataone.service.exceptions.InvalidRequest;
+import org.dataone.service.exceptions.NotAuthorized;
 import org.dataone.service.exceptions.NotFound;
 import org.dataone.service.exceptions.ServiceFailure;
 import org.dataone.service.types.v1.Group;
@@ -585,7 +586,7 @@ public class D1ResourceHandler {
         // TODO: Use content negotiation to determine which return format to use
         response.setContentType("text/xml");
         response.setStatus(e.getCode());
-        if( e instanceof NotFound) {
+        if( e instanceof NotFound || e instanceof NotAuthorized) {
             logMetacat.info("D1ResourceHandler: Serializing exception with code " + e.getCode() + ": " + e.getMessage());
         } else {
             logMetacat.error("D1ResourceHandler: Serializing exception with code " + e.getCode() + ": " + e.getMessage(), e);

@taojing2002 could you take a look doing this for the next release of Metacat? I think it'd be a nice improvement.

mbjones commented 10 months ago

@artntek This relates to our conversation the other day on logging verbosity and stack traces.