Commit 029770b2 by Anton Sudak

Improve logging

parent 776a20ba
......@@ -55,18 +55,16 @@ public class Template {
* @return block
*/
public static <T extends AbstractBlock> T addBlockToSlot(Class<T> blockClass, AbstractBlock parentBlock, String slot) {
if (parentBlock == null) {
throw new RuntimeException("Cannot add new block to slot: Parent is null!");
}
Objects.requireNonNull(parentBlock, "Cannot add new block to slot: Parent is null!");
T newBlock = (T) AbstractBlock.find.byParentAndSlot(parentBlock, slot);
if (newBlock == null) {
try {
logger.info("Creating a new " + blockClass.getSimpleName() + " for parent " + parentBlock.getId() + " and slot " + slot);
logger.info("Creating a new {} for parent {} and slot {}", blockClass.getSimpleName(), parentBlock.getId(), slot);
newBlock = blockClass.newInstance();
} catch (Exception e) {
logger.error("Could not instantiate new block of type: " + blockClass.getName(), e);
logger.error("Could not instantiate new block of type: {}", blockClass.getName(), e);
e.printStackTrace();
}
newBlock.setSlot(slot);
......@@ -80,9 +78,6 @@ public class Template {
// Fixes JPA constraint violation error when trying to delete
// a page block with just initialized slots on that page
JPA.em().getEntityManagerFactory().getCache().evict(parentBlock.getClass(), parentBlock.getId());
} else {
logger.debug("Adding existing " + blockClass.getName() + " for parent " + parentBlock.getId() + " and slot " + slot);
}
return newBlock;
......@@ -99,7 +94,7 @@ public class Template {
T newBlock = (T) AbstractBlock.find.byKey(key);
if (newBlock == null) {
logger.info("Creating a new " + blockClass.getName() + " with key " + key);
logger.info("Creating a new {} with key {}", blockClass.getName(), key);
try {
newBlock = blockClass.newInstance();
......@@ -109,12 +104,10 @@ public class Template {
newBlock.save();
} catch (Exception e) {
logger.error("Could not create new block of type: " + blockClass.getName(), e);
logger.error("Could not create new block of type: {}", blockClass.getName(), e);
e.printStackTrace();
}
} else {
logger.debug("Adding existing " + blockClass.getName() + " with key " + key);
}
return newBlock;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment