Skip to content

Commit

Permalink
[MNT-24306] log4j2 debug log fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
purusothaman-mm committed May 9, 2024
1 parent 3407851 commit 29ccc52
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.Level;

/**
* A basic component that will be started for this module.
Expand All @@ -36,7 +38,7 @@
* @author Maurizio Pillitu
*/
public class DemoComponent extends AbstractModuleComponent {
private static Log logger = LogFactory.getLog(DemoComponent.class);
private static Logger logger = LogManager.getLogger(DemoComponent.class);

private NodeService nodeService;

Expand All @@ -55,6 +57,7 @@ public void setNodeLocatorService(NodeLocatorService nodeLocatorService) {
*/
@Override
protected void executeInternal() throws Throwable {
Configurator.setLevel(logger.getName(), Level.DEBUG);
System.out.println("DemoComponent has been executed");
logger.debug("Test debug logging. Congratulation your JAR Module is working");
logger.info("This is only for information purposes. Better remove me from the log in Production");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.Level;


import java.util.HashMap;
import java.util.Map;
Expand All @@ -37,13 +40,14 @@
* @since 2.1.0
*/
public class HelloWorldWebScript extends DeclarativeWebScript {
private static Log logger = LogFactory.getLog(HelloWorldWebScript.class);
private static Logger logger = LogManager.getLogger(HelloWorldWebScript.class);

protected Map<String, Object> executeImpl(
WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("fromJava", "HelloFromJava");

Configurator.setLevel(logger.getName(), Level.DEBUG);
logger.debug("Your 'Hello World' Web Script was called!");

return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.Level;

/**
* A basic component that will be started for this module.
Expand All @@ -36,7 +38,7 @@
* @author Maurizio Pillitu
*/
public class DemoComponent extends AbstractModuleComponent {
private static Log logger = LogFactory.getLog(DemoComponent.class);
private static Logger logger = LogManager.getLogger(DemoComponent.class);

private NodeService nodeService;

Expand All @@ -55,6 +57,7 @@ public void setNodeLocatorService(NodeLocatorService nodeLocatorService) {
*/
@Override
protected void executeInternal() throws Throwable {
Configurator.setLevel(logger.getName(), Level.DEBUG);
System.out.println("DemoComponent has been executed");
logger.debug("Test debug logging. Congratulation your JAR Module is working");
logger.info("This is only for information purposes. Better remove me from the log in Production");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.Level;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -37,13 +39,14 @@
* @since 2.1.0
*/
public class HelloWorldWebScript extends DeclarativeWebScript {
private static Log logger = LogFactory.getLog(HelloWorldWebScript.class);
private static Logger logger = LogManager.getLogger(HelloWorldWebScript.class);

protected Map<String, Object> executeImpl(
WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("fromJava", "HelloFromJava");

Configurator.setLevel(logger.getName(), Level.DEBUG);
logger.debug("Your 'Hello World' Web Script was called!");

return model;
Expand Down

0 comments on commit 29ccc52

Please sign in to comment.