Skip to content

Commit

Permalink
Merge pull request #838 from Dev-ALPM/logger-optimization
Browse files Browse the repository at this point in the history
Logger optimization
  • Loading branch information
rsoika authored Sep 29, 2023
2 parents 8c5c9c5 + 8b0f111 commit 2459d1e
Show file tree
Hide file tree
Showing 115 changed files with 1,080 additions and 1,016 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -87,7 +88,7 @@
public class ItemCollection implements Cloneable {
// NOTE: ItemCollection is not serializable

private static Logger logger = Logger.getLogger(ItemCollection.class.getName());
private static final Logger logger = Logger.getLogger(ItemCollection.class.getName());

private Map<String, List<Object>> hash = new Hashtable<String, List<Object>>();

Expand Down Expand Up @@ -229,7 +230,7 @@ public void cloneItem(String itemName, ItemCollection source) {
List<Object> copy = (List<Object>) ois.readObject();
hash.put(itemName, copy);
} catch (IOException | ClassNotFoundException e) {
logger.warning("Unable to clone values of Item '" + itemName + "' - " + e);
logger.log(Level.WARNING, "Unable to clone values of Item ''{0}'' - {1}", new Object[]{itemName, e});
}
}

Expand Down Expand Up @@ -1626,8 +1627,9 @@ private void setItemValue(String itemName, Object itemValue, boolean append, boo
// test if value is ItemCollection
if (itemValue instanceof ItemCollection) {
// just warn - do not remove
logger.warning("replaceItemValue '" + itemName
+ "': ItemCollection can not be stored into an existing ItemCollection - use XMLItemCollection instead.");
logger.log(Level.WARNING, "replaceItemValue ''{0}'':"
+ " ItemCollection can not be stored into an existing"
+ " ItemCollection - use XMLItemCollection instead.", itemName);
}

// test if value is a Set
Expand All @@ -1638,7 +1640,8 @@ private void setItemValue(String itemName, Object itemValue, boolean append, boo

// test if value is serializable
if (!(itemValue instanceof java.io.Serializable)) {
logger.warning("replaceItemValue '" + itemName + "': object is not serializable!");
logger.log(Level.WARNING, "replaceItemValue ''{0}'':"
+ " object is not serializable!", itemName);
this.removeItem(itemName);
return;
}
Expand All @@ -1652,8 +1655,9 @@ private void setItemValue(String itemName, Object itemValue, boolean append, boo
for (int i = 0; i < itemValueList.size(); i++) {
if (itemValueList.get(i) instanceof ItemCollection) {
// just warn - do not remove
logger.warning("replaceItemValue '" + itemName
+ "': ItemCollection can not be stored into an existing ItemCollection - use XMLItemCollection instead.");
logger.log(Level.WARNING, "replaceItemValue ''{0}'':"
+ " ItemCollection can not be stored into an existing"
+ " ItemCollection - use XMLItemCollection instead.", itemName);
}
}
} else {
Expand All @@ -1665,9 +1669,9 @@ private void setItemValue(String itemName, Object itemValue, boolean append, boo
// now we can be sure the itemValue is an instance of List
convertItemValue(itemValueList);
if (!validateItemValue(itemValueList)) {
String message = "setItemValue failed for item '" + itemName
+ "', the value is a non supported object type: " + itemValue.getClass().getName() + " value="
+ itemValueList;
String message = new StringBuilder("setItemValue failed for item '").append(itemName)
.append("', the value is a non supported object type: ").append(itemValue.getClass().getName())
.append(" value=").append(itemValueList).toString();
logger.warning(message);
throw new InvalidAccessException(message);
}
Expand Down Expand Up @@ -1855,10 +1859,10 @@ private Object deepCopyOfMap(Map<String, List<Object>> map) {
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (IOException e) {
logger.warning("Unable to clone values of ItemCollection - " + e);
logger.log(Level.WARNING, "Unable to clone values of ItemCollection - {0}", e);
return null;
} catch (ClassNotFoundException e) {
logger.warning("Unable to clone values of ItemCollection - " + e);
logger.log(Level.WARNING, "Unable to clone values of ItemCollection - {0}", e);
return null;
}
}
Expand Down Expand Up @@ -1909,7 +1913,7 @@ private static String getStringValueFromMap(Map<String, List<Object>> hash, Stri
}
} else {
// Value is not a list!
logger.warning("getStringValueFromMap - wrong value object found '" + aName + "'");
logger.log(Level.WARNING, "getStringValueFromMap - wrong value object found ''{0}''", aName);
return obj.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class RuleEngine {
public static final String INVALID_SCRIPT = "INVALID_SCRIPT";
private static final HashSet<Class<?>> BASIC_OBJECT_TYPES = getBasicObjectTypes();

private static Logger logger = Logger.getLogger(RuleEngine.class.getName());
private static final Logger logger = Logger.getLogger(RuleEngine.class.getName());

private Context _context = null;
private String languageId;
Expand Down Expand Up @@ -143,7 +143,7 @@ public Context getContext() {
.option("engine.WarnInterpreterOnly", "false") //
.allowAllAccess(true) //
.build();
logger.info("...init RuleEngine took " + (System.currentTimeMillis()-l) + "ms");
logger.log(Level.INFO, "...init RuleEngine took {0}ms", System.currentTimeMillis()-l);
}
return _context;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ public boolean evaluateBooleanExpression(String script, ItemCollection workitem)
}

if (debug) {
logger.finest("......SCRIPT:" + script);
logger.log(Level.FINEST, "......SCRIPT:{0}", script);
}

// Test if we have a deprecated Script...
Expand All @@ -197,7 +197,7 @@ public boolean evaluateBooleanExpression(String script, ItemCollection workitem)
try {
result = eval(script);
} catch (PolyglotException e) {
logger.warning("Script Error in: " + script);
logger.log(Level.WARNING, "Script Error in: {0}", script);
// script not valid
throw new PluginException(RuleEngine.class.getSimpleName(), INVALID_SCRIPT,
"BusinessRule contains invalid script:" + e.getMessage(), e);
Expand Down Expand Up @@ -239,7 +239,7 @@ public ItemCollection evaluateBusinessRule(String script, ItemCollection workite
}

if (debug) {
logger.finest("......SCRIPT: " + script);
logger.log(Level.FINEST, "......SCRIPT: {0}", script);
}

// Test if we have a deprecated Script...
Expand All @@ -255,7 +255,7 @@ public ItemCollection evaluateBusinessRule(String script, ItemCollection workite
ItemCollection result = convertResult();
return result;
} catch (PolyglotException e) {
logger.warning("Script Error: " + e.getMessage() + " in: " + script);
logger.log(Level.WARNING, "Script Error: {0} in: {1}", new Object[]{e.getMessage(), script});
// script not valid
throw new PluginException(RuleEngine.class.getSimpleName(), INVALID_SCRIPT,
"BusinessRule contains invalid script:" + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class RuleEngineNashornConverter {

private static Logger logger = Logger.getLogger(RuleEngineNashornConverter.class.getName());
private static final Logger logger = Logger.getLogger(RuleEngineNashornConverter.class.getName());

/**
* This method returns true if the script is detected as deprecated. A
Expand Down Expand Up @@ -114,12 +114,12 @@ public static boolean isDeprecatedScript(String script) {
*/
public static String rewrite(String script, ItemCollection workitem, ItemCollection event) {

String converterLog="";
converterLog=converterLog+"\n***************************************************";
converterLog=converterLog+"\n*** DEPRECATED NASHORN SCRIPT FOUND: ***";
converterLog=converterLog+"\n***************************************************\n";
StringBuilder converterLog = new StringBuilder()
.append("\n***************************************************")
.append("\n*** DEPRECATED NASHORN SCRIPT FOUND: ***")
.append("\n***************************************************\n")

converterLog=converterLog+"\n" + script + "\n\n";
.append("\n").append(script).append("\n\n");

script = convertByItemCollection(script, workitem, "workitem");
script = convertByItemCollection(script, event, "event");
Expand All @@ -128,12 +128,12 @@ public static String rewrite(String script, ItemCollection workitem, ItemCollect
// is the result. We need to remove the [0] here!
script = script.replace(")[0]", ")");

converterLog=converterLog+"\n***************************************************";
converterLog=converterLog+"\n*** PLEASE REPLACE YOUR SCRIPT WITH: ***";
converterLog=converterLog+"\n***************************************************\n";
converterLog=converterLog+"\n" + script + "\n";
converterLog=converterLog+"\n***************************************************\n";
logger.warning(converterLog);
converterLog.append("\n***************************************************")
.append("\n*** PLEASE REPLACE YOUR SCRIPT WITH: ***")
.append("\n***************************************************\n")
.append("\n").append(script).append("\n")
.append("\n***************************************************\n");
logger.warning(converterLog.toString());
return script;

}
Expand Down
Loading

0 comments on commit 2459d1e

Please sign in to comment.