Move packagesToKeep to a system-property/env-var

This commit is contained in:
2023-11-15 08:49:04 -06:00
parent d2fd0d13b5
commit 1b58cdeb3c

View File

@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier; import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier;
@ -34,6 +35,17 @@ import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier;
*******************************************************************************/ *******************************************************************************/
public class LogUtils public class LogUtils
{ {
///////////////////////////////////////////////////////////////////////////////////////////////
// This string will be used in regex, inside ()'s, so you can supply pipe-delimited packages //
// as in, com.kingsrook|com.yourdomain|org.some.other.package //
///////////////////////////////////////////////////////////////////////////////////////////////
private static String packagesToKeep = ".";
static
{
packagesToKeep = new QMetaDataVariableInterpreter().getStringFromPropertyOrEnvironment("qqq.logger.packagesToKeep", "QQQ_LOGGER_PACKAGES_TO_KEEP", ".");
}
/******************************************************************************* /*******************************************************************************
** **
@ -118,7 +130,6 @@ public class LogUtils
{ {
try try
{ {
String packagesToKeep = "com.kingsrook|com.coldtrack"; // todo - parameterize!!
StringBuilder rs = new StringBuilder(); StringBuilder rs = new StringBuilder();
String[] lines = stackTrace.split("\n"); String[] lines = stackTrace.split("\n");
@ -134,7 +145,13 @@ public class LogUtils
{ {
keepLine = false; keepLine = false;
indexWithinSubStack++; indexWithinSubStack++;
if(line.matches("^\\s+at (" + packagesToKeep + ").*"))
/////////////////////////////////////////////////////////////////////////////
// avoid NPE on packages to keep (and keep all packages) //
// also, avoid the regex call if it's the default of "." (e.g., match all) //
// otherwise, check if the line matches "at (packagesToKeep).*" //
/////////////////////////////////////////////////////////////////////////////
if(packagesToKeep == null || ".".equals(packagesToKeep) || line.matches("^\\s+at (" + packagesToKeep + ").*"))
{ {
keepLine = true; keepLine = true;
} }