This is a framework that automates our Apex logging powered by Platform Event.
Apex debug logs will be inserted to a custom object, such as EAL_Logger__c
.
Use Platform Events only if the debug log contains the ERROR
LoggingLevel.
Platform Event has some allocations, especially "Event Publishing: maximum number of event notifications published per hour" is one of the most inescapable allocations. So we need to reduce its frequency as much as possible.
sfdx force:package:install -p event-based-apex-logger@1.0.3.0 -s AllUsers -u [targetusername]
sfdx force:package:install:report -i 0HfXXXXXXXXXXXXXXX -u [targetusername]
sfdx force:org:open -p lightning/setup/ImportedPackage/home -u [targetusername]
sfdx force:user:permset:assign -n EAL_Logger_User -u [targetusername]
sfdx force:org:open -p lightning/setup/CustomMetadata/home -u [targetusername]
sfdx force:org:open -u demo -p lightning/o/EAL_Logger__c/list -u [targetusername]
public with sharing class Demo {
private final EAL_Logger logger = EAL_Logger.getInstance();
private void setMethodName(String methodName) {
logger.setClassName(Demo.class.getName());
logger.setMethodName(methodName);
}
public void runDemo() {
this.setMethodName('demo');
try {
Account account = new Account();
insert account;
} catch (Exception e) {
logger.store(LoggingLevel.ERROR, EAL_CommonError.createErrorMessage(e));
} finally {
logger.publish();
logger.clear();
}
}
}
sfdx force:package:create -d "This is a framework that automates our Apex logging powered by Platform Event." -e -n "event-based-apex-logger" -r force-app-eal -t Unlocked -v DevHub-EAL
sfdx force:package:version:create -a "Summer '20" -b "master" -c -e "Summer '20 (API version 49.0)" -f config/project-scratch-def.json -n 1.0.0.0 -p 0HoXXXXXXXXXXXXXXX -t v49.0 -v DevHub-EAL -x --postinstallurl "https://github.com/takahitomiyamoto/event-based-apex-logger" --releasenotesurl "https://github.com/takahitomiyamoto/event-based-apex-logger/releases"
sfdx force:package:version:create:report -i 08cXXXXXXXXXXXXXXX -v DevHub-EAL
sfdx force:package:version:create:list -s Success -v DevHub-EAL
sfdx force:package:version:promote -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL
sfdx force:package:version:report -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL --verbose
sfdx force:package:list -v DevHub-EAL --verbose
sfdx force:package:version:list -p event-based-apex-logger -v DevHub-EAL --verbose
sfdx force:package:version:create -a "Winter '21" -b "master" -c -e "Winter '21 (API version 50.0)" -f config/project-scratch-def.json -n 1.0.3.0 -p 0HoXXXXXXXXXXXXXXX -t v50.0 -v DevHub-EAL -x --postinstallurl "https://github.com/takahitomiyamoto/event-based-apex-logger" --releasenotesurl "https://github.com/takahitomiyamoto/event-based-apex-logger/releases"
sfdx force:package:version:create:report -i 08cXXXXXXXXXXXXXXX -v DevHub-EAL
sfdx force:package:version:update -a "Winter '21" -b "master" -e "Winter '21 (API version 50.0)" -p 04tXXXXXXXXXXXXXXX -t v50.0 -v DevHub-EAL
sfdx force:package:version:promote -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL
sfdx force:package:version:list -p event-based-apex-logger -v DevHub-EAL --verbose