Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
id0

Logger writes information in log file.

What does this section cover?

Table of Contents

Define a logger

A logger is defined in the following path: project_name/src/main/resources/metadata/logbackloggers.xml:
-loggername and logbackappenderfilename must be unique
-logbackclassname must be defined only once

Code Block
titleDefine logger
collapsetrue
<logbackconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/applications.xsd">
       <logbackloggers> 
               <logbacklogger>
                       <loggername>kounta</loggername>
                       <logbackappenderfilename>kounta</logbackappenderfilename>
                       <logbackclasses>
                              <logbackclass>
                                     <logbackclassname>com.crm.kounta.webapi.KOUNTAUtilBean</logbackclassname>
                              </logbackclass>
                       </logbackclasses> 
               </logbacklogger>
       </logbackloggers>
</logbackconfig>

Update pom.xml

Code Block
titleUpdate pom.xml
collapsetrue
....
<dependencies>
....
	<dependency>
	    <groupId>ch.qos.logback</groupId>
	    <artifactId>logback-core</artifactId>
	    <version>1.2.3</version>
	    <scope>provided</scope>
	</dependency>
	
	<dependency>
	    <groupId>ch.qos.logback</groupId>
	    <artifactId>logback-classic</artifactId>
	    <version>1.2.3</version>
	    <scope>provided</scope>
	</dependency>

Retrieve logger

To retrieve the current CRM Session object you have to use getCRMSession() method which is implemented in com.crm.businessobject.CRMBase super class. Note that all CRMBO, CRMUI, CRMProcess and CRMAPIBean classes extend CRMBase.

Code Block
titleRetrieve CRM Session
collapsetrue
 public CRMDO copy(CRMDO dto)
{
	CRMSession session = getCRMSession(</dependencies>	

Disable standalone configuration:

Add the following in standalone.xml under wildfly\standalone\configuration :

Code Block
titleDisable standalone configuration
collapsetrue
<subsystem xmlns="urn:jboss:domain:logging:3.0">
	<add-logging-api-dependencies value="false"/>
	<use-deployment-logging-config value="false"/>
	.......
</subsystem>

Invoke the logger object

If the file extends CRMBase:

Code Block
titleUse logger
collapsetrue
public void doSomething(CRMDOAccountingPeriod accountingPeriod) throws Exception {
	logger.debug("Invoked doSomething()");
	...
}

Use logger

After retrieving the CRM Session, you can use it to get information about the logged in user, the server, the database and the general and formatting settings.If the file does not extend CRMBase:

Code Block
titleExample 1 - Logged In UserUse logger
collapsetrue
public CRMDOvoid copydoSomething(CRMDOCRMDOAccountingPeriod dtoaccountingPeriod) throws Exception {
	CRMSessionLogger sessionlogger = LogUtil.getLogger(getCRMSession(), getClass());
	iflogger.debug( dto instanceof CUSTOMCRMDORentalTypeProduct)
	{
		CUSTOMCRMDORentalTypeProduct oldProduct = (CUSTOMCRMDORentalTypeProduct) dto;
		CUSTOMCRMDORentalTypeProduct newProduct = (CUSTOMCRMDORentalTypeProduct)oldProduct.clone();
		newProduct.setCreatedDate(getCurrentDate());
		newProduct.setCreatedByUnit(session.getUnit());
		newProduct.setCreatedByUser(ejbSession.getLoggedUser"Invoked doSomething()");
	...
}

If the file is not related to an organisation:

Code Block
titleUse logger
collapsetrue
public void doSomething(CRMDOAccountingPeriod accountingPeriod) throws Exception {
	Logger logger = LogUtil.getLogger(getClass());
	logger.debug("Invoked doSomething()");
	...
}

If the method/file is asynchronous:

Code Block
titleUse logger
collapsetrue
@Asynchronous
public void execute(@Observes(during=TransactionPhase.AFTER_SUCCESS)  WorkflowRuleEvent event) {
	setLogger(event.getSession());
		newProductlogger.setUpdatedByUnit(null);
		newProduct.setUpdatedByUser(nulldebug("Invoked execute()");
		newProduct.setUpdatedDate(null);
	}...
}