Code Monkey home page Code Monkey logo

acmn_error_logger's Introduction

Salesforce Error Logger Utility

Used to write to a custom object for error logging outside of debug.
Includes support for Platform Events as well as passing in an exception directly into the static helper class.

Settings are managed via Custom Metadata Types. By default, logging is turned off.

Deploy to Salesforce

Enabling for users

For logging to be enabled, the users must be added to the permission set ACMN Logging Enabled. This permission set gives the user the ability to create the specific platform event records used by the default implementation.

If the permission set is not assigned to a user, System.debug will still log the message. No need to have separate debug and logging statements.

Logging in Apex

Simple Exception logging:

  • ACMN_Error_Logger.Log(Exception ex);
  • ACMN_Error_Logger.Log('my error message')

Simple example in context (You can run this using anonymous apex):

try{
    insert new Account(); // this will fail
} catch(Exception ex){
    ACMN_Error_Logger.Log(ex);
}

A more verbose example includes support for bulk logging and custom error log field values:

try{
    insert new Account(); // this will fail
} catch(Exception ex){
    ACMN_LogRecord rec = new ACMN_LogRecord(ex, 'anon apex', 'ran this in dev console');
    ACMN_Error_Logger.Log(new List<ACMN_LogRecord>{rec});
}

Logging elsewhere

The beauty of using platform events is that you can create one from a flow or an external system. You can also write your own plugins using the plugin service class and Custom Metadata Type to implement your own logic.

Custom Services

You can build your own custom logging services instead of using Platform Events and the default logic. Take a look at ACMN_Logger_Service_PE.cls for an example of how to implement your own. Basically, you must create a custom class that extends the ACMN_Logger_Service class.

global abstract class ACMN_Logger_Service {
    global abstract void processRecords(List<String> recordsAsJSON);
}

Once this is done, you need to create a new Custom Metadata Type ACMN_Logger_Setting record where you define the following:

  • Logger Service Class (API Name)
  • Use Custom Permissions (Boolean)
  • Custom Permission API Name (if Use Custom Permissions is checked)

Updates

  • Added support for toggling logging on and off via Custom MetaData Types
  • Added generic method for logging a simple string message. Use ACMN_Error_Logger.Log('my error message')
  • Added Report to display error logs
  • Better support for bulk error logging
  • Adding support for custom logging modules / plugins (these will be implementations of abstract classes). Take a look at ACMN_Logger_Service_PE.cls as an example of how to implement your own logging service.
    • Custom logging services must have a related ACMN_Logger_Setting Custom Metadata Type record.

In Progress

  • Managed Package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.