Versions Compared

Key

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

...

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>

...

Use 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.If the file extends CRMBase:

Code Block
titleRetrieve CRM SessionUse logger
collapsetrue
 publicpublic CRMDOvoid copydoSomething(CRMDOCRMDOAccountingPeriod dtoaccountingPeriod) throws Exception {
	CRMSession session = getCRMSession();
	...
}

Use logger

...

logger.debug("Invoked doSomething()");
}

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();, 	if( dto instanceof CUSTOMCRMDORentalTypeProduct)
	{
		CUSTOMCRMDORentalTypeProduct oldProduct = (CUSTOMCRMDORentalTypeProduct) dto;
		CUSTOMCRMDORentalTypeProduct newProduct = (CUSTOMCRMDORentalTypeProduct)oldProduct.clone();
		newProduct.setCreatedDate(getCurrentDate());
		newProduct.setCreatedByUnit(session.getUnit());
		newProduct.setCreatedByUser(ejbSession.getLoggedUsergetClass());
	logger.debug("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());
		newProductlogger.setUpdatedByUnit(null);
		newProduct.setUpdatedByUser(null);
		newProduct.setUpdatedDate(null);
	}debug("Invoked doSomething()");
}