Skip to content

This is a framework that automates our Apex logging powered by Platform Event.

License

Notifications You must be signed in to change notification settings

takahitomiyamoto/event-based-apex-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dependencies status devDependency status Code Climate codecov

GitHub issues GitHub forks GitHub stars GitHub license

Twitter

Event-based Apex Logger

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.

Remarks

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.

Platform Event Allocations

How to use

1. install the framework on your org

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]

2. assign the permission set to one or more users of your org

sfdx force:user:permset:assign -n EAL_Logger_User -u [targetusername]

3. configure the custom metadata type : EAL_LoggerConfig

sfdx force:org:open -p lightning/setup/CustomMetadata/home -u [targetusername]

logger-config

4. execute any apex code and see the custom tab : EAL_Loggers

sfdx force:org:open -u demo -p lightning/o/EAL_Logger__c/list -u [targetusername]

Sample Code

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();
    }
  }
}

sample-code

Acknowledgment


Appendix: How to create a package

1. create a package

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

2. create a package version

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"

3. retrieve details about a package version creation request

sfdx force:package:version:create:report -i 08cXXXXXXXXXXXXXXX -v DevHub-EAL

4. list package version creation requests

sfdx force:package:version:create:list -s Success -v DevHub-EAL

5. promote a package version to released

sfdx force:package:version:promote -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL

6. retrieve details about a package version in the Dev Hub org

sfdx force:package:version:report -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL --verbose

7. list all packages in the Dev Hub org

sfdx force:package:list -v DevHub-EAL --verbose

8. list all package versions in the Dev Hub org

sfdx force:package:version:list -p event-based-apex-logger -v DevHub-EAL --verbose

Appendix: How to update a package

1. create a package version

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"

2. retrieve details about a package version creation request

sfdx force:package:version:create:report -i 08cXXXXXXXXXXXXXXX -v DevHub-EAL

3. update a package version

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

4. promote a package version to released

sfdx force:package:version:promote -p 04tXXXXXXXXXXXXXXX -v DevHub-EAL

5. list all package versions in the Dev Hub org

sfdx force:package:version:list -p event-based-apex-logger -v DevHub-EAL --verbose

About

This is a framework that automates our Apex logging powered by Platform Event.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published