Following is a reference of methods that you can use in your Apex Logging to capture the right data in your Apex-based monitors
Instance Methods
Instance methods are all found in the EventLogger class and are used in classic event logging use cases.
- void log(String logString)
- void log(String logString, String logLevel)
- void log(List<String> logList)
- void log(List<String> logList, String logLevel)
- void logSpace()
- void logException (Exception e)
- void setSummaryLog(String summaryLog)
- void setPrimaryRecordId(Id primaryRecordId)
- void setEventId(String eventId)
- void setRunningUser(User runningUser)
- void logPopulatedFields(SObject objRecord)
- void logPopulatedFields(List<SObject> objRecordList)
- void logPopulatedFields(SObject objRecord, List<String> fieldNames)
- void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
- void setNeedsReview(boolean value)
- cancelEvent()
- void reportToSightLane()
- void reportFailureToSightLane()
- void reportFailureToSightLane(Exception e)
- void reportFailureToSightLane(Exception e, boolean addExceptionToLog)
Static Methods
Static methods are all found in the Logging class and are used in static logging use cases.
- void log(String logString)
- void log(String logString, String logLevel)
- void log(List<String> logList)
- void log(List<String> logList, String logLevel)
- void logSpace()
- void setNeedsReview()
- void logException(Exception e)
- void logPopulatedFields(SObject objRecord)
- void logPopulatedFields(List<SObject> objRecordList)
- void logPopulatedFields(SObject objRecord, List<String> fieldNames)
- void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
- EventLogger startLog(String monitorName)
- EventLogger startLog(String monitorName, Id primaryRecordId)
- EventLogger getCurrentEventLogger(String newMonitorName)
- EventLogger getCurrentEventLogger(String newMonitorName, String newPrimaryRecord)
- void reportToSightLane(String monitorName, String logStatement)
- void reportFailureToSightLane(String monitorName, String logStatement)
- void reportFailureToSightLane(String monitorName, String logStatement, Exception e)
- void reportToSightLane(String monitorName, List<String> logStatements)
- void reportFailureToSightLane(String monitorName, List<String> logStatements)
- void reportFailureToSightLane(String monitorName, List<String> logStatements, Exception e)
- void reportToSightLane(String monitorName, String logStatement, SObject record)
- void reportFailureToSightLane(String monitorName, String logStatement, SObject record)
- void reportFailureToSightLane(String monitorName, String logStatement, Exception e, SObject record)
- void reportToSightLane(String monitorName, List<String> logStatements, SObject record)
- void reportFailureToSightLane(String monitorName, List<String> logStatements, SObject record)
- void reportFailureToSightLane(String monitorName, List<String> logStatements, Exception e, SObject record)
Instance Method Name |
void log(String logString) Add a simple log statement eventLogger.log('This is my statement'); Result: 2021-08-02 18:25:30 | This is my statement |
void log(String logString, String logLevel) Add a simple log statement and level to the current log eventLogger.log('This is my statement','Error'); Result: 2021-08-02 18:25:30 | [Error] This is my statement |
void log(List<String> logList)
Add a collection of string values to the existing log as separate log statements eventLogger.log(new List<String>{'This is my statement', 'This is my other statement'}); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void log(List<String> logList, String logLevel)
Add a collection of string values and a logLevel to the existing log as separate log statements eventLogger.log(new List<String>{'This is my statement', 'This is my other statement'},'Error'); Result: 2021-08-02 18:25:30 | [Error] This is my statement 2021-08-02 18:25:30 | [Error] This is my other statement |
void logSpace()
Add a break between groups of log statements. Helpful for readability in longer logs with lots of content. eventLogger.log('This is my statement','Error'); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void logException (Exception e)
Formats logging of exception content to include Exception Type, Line Number, and Message eventLogger.logException(e); Result: 20:24:25 | [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
void setSummaryLog(String summaryLog)
Sets an Event's Event Log Summary value. A simple statement about the results of an event. eventLogger.setSummaryLog('The process completed successfully'); Result: (Event Summary field value updated) |
void setPrimaryRecordId(Id primaryRecordId)
Sets an Event's Primary Record Id value. Associates this log with a specific data record. eventLogger.setPrimaryRecordId(myObect.Id); Result: (Primary Record Id field value updated) |
void setEventId(String eventId)
Sets the Event's Event Id value. Event Id refers to a user defined string that uniquely identifies this process. Any future logs of the same type and Event Id will append their logs to the existing Event. eventLogger.setEventId('myuniquecontextid1234567890'); Result: (Logs are appended to the existing Event with the same id) |
void setRunningUser(User runningUser)
Sets the Event's running User. runningUser refers to an instance of the User object (not just an id). This is helpful for Platform Event triggers and other processes that list Automated Process or a generic Integration User as the Event user. eventLogger.setRunningUser(intendedUserVariable); Result: (The event will be recorded as having been run by the supplied User) |
void logPopulatedFields(SObject objRecord)
Adds all populated field values for the supplied instance object, to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |LastName - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList)
Adds all populated field values for the supplied instance objects, to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |FirstName - Christiano 2021-08-02 18:25:30 |LastName - Ronaldo 2021-08-02 18:25:30 |Email - cr@bestever.com |
void logPopulatedFields(SObject objRecord, List<String> fieldNames)
Adds all populated specified field values for the supplied instance object, to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
Adds all populated field values for the supplied instance objects, to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |Email - cr@bestever.com |
void setNeedsReview(boolean needsReview)
Sets the Needs Review flag for events. Allows for notifications, even when there has NOT been an exception. eventLogger.setNeedsReview(true); Result: (Needs Review field value updated, Result icon changed in interface) |
void cancelEvent()
removes the Event from the Event Queue. Any calls to reportToSightLane or reportFailureToSightLane after a call to cancelEvent will result in a * SightLane Alert * event but will not persist the actual event logs. eventLogger.cancelEvent() Result: (The event is removed from the Event Queue and will not be saved) |
void reportToSightLane()
Commits all logs to SightLane and saves the new Event. Usually called at the end of a process. eventLogger.log('This is my statement'); Result: (Event record saved with all log statements) |
void reportFailureToSightLane()
Commits all logs to SightLane and saves the new Event with a status of 'Failed'. This version of the method is used to report an event as failed for logical or strategic reasons (when there has not been an exception). Warning: Mistaking this method for the version that takes an Exception parameter is a common mistake! if(getMyCriticalRecords().size() == 0){ Result: (Event created in a Failed status. Result icon changed in the user interface) |
void reportFailureToSightLane(Exception e)
Commits all logs to SightLane and saves the new Event with a status of 'Failed'. Usually called at the end of a process and usually utilized within appropriate exception handling try{ Result: (Event in a Failed status. Exception data added to log. Result icon changed in interface) |
void reportFailureToSightLane(Exception e, boolean addExceptionToLog)
Commits all logs to SightLane and saves the new Event with a status of 'Failed'. Usually called at the end of a process and usually utilized within appropriate exception handling. The second parameter determines whether the exception information is added directly to the log content. If this is false, Stack Trace information will only be stored on the Event record and will be viewable in the source viewer component. try{ Result: (Event in a Failed status. Exception data added to log. Result icon changed in interface) |
Static methods are used for two primary reasons:
- To establish a new monitor/logger within your Apex code
- To add log statements to the "current" log. For example, if you establish and complete a monitor in your controller method, and you want to add a log statements regarding functionality or logic that exists within a helper method that is called by the controller, use the static version of the log method. This allows a helper method's logs to be added to the monitor of the calling method.
Static Method Name |
static void log(String logString) Add a simple log statement to the current log SightLane.Logging.log('This is my statement'); Result: 2021-08-02 18:25:30 | This is my statement |
static void log(String logString, String logCategory) Add a simple log statement and category to the current log SightLane.Logging.log('This is my statement','Error'); Result: 2021-08-02 18:25:30 | [Error] This is my statement |
void log(List<String> logList)
Add a collection of string values to the existing log as separate log statements SightLane.Logging.log(new List<String>{'This is my statement', 'This is my other statement'}); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void log(List<String> logList, String category)
Add a collection of string values and a category to the existing log as separate log statements SightLane.Logging.log(new List<String>{'This is my statement', 'This is my other statement'},'Error'); Result: 2021-08-02 18:25:30 | [Error] This is my statement 2021-08-02 18:25:30 | [Error] This is my other statement |
void logSpace()
Add a break between groups of log statements. Helpful for readability in longer logs with lots of content. SightLane.Logging.log('This is my statement','Error'); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void setNeedsReview(boolean needsReview)
Sets the Needs Review flag for an Event. Allows for notifications, even when there has NOT been an exception. Warning: Only relevant IF a logger has already been created SightLane.Logging.setReviewFlag(true); Result: (Needs Review field value updated, Result icon changed in interface) |
void logException (Exception e)
Formats logging of exception content to include Exception Type, Line Number, and Message Warning: Only relevant IF a logger has already been created SightLane.Logging.logException(e); Result: 20:24:25 | [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
void logPopulatedFields(SObject objRecord)
Adds all populated field values for the supplied instance object to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |LastName - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList)
Adds all populated field values for the supplied instance objects to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |FirstName - Christiano 2021-08-02 18:25:30 |LastName - Ronaldo 2021-08-02 18:25:30 |Email - cr@bestever.com |
void logPopulatedFields(SObject objRecord, List<String> fieldNames)
Adds all populated specified field values for the supplied instance object, to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
Adds all populated field values for the supplied instance objects to the logs for this Event Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com'); Result: 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |Email - cr@bestever.com |
EventLogger startLog(String monitorName)
Creates a new Event record instance to which logs can be added EventLogger el = sightlane.Logging.startLog('My New Monitor'); Result: (A new Event record is created. A new Monitor record is created, if necessary) |
EventLogger startLog(String monitorName, Id primaryRecordId)
Creates a new Event record instance to which logs can be added. Associate the Event with a particular data record for easier debugging. Note: This is not appropriate for All monitors (for example a batch job), but should be used as often as possible to support faster debugging and clear association between logs and data issues. Contact contact = getMyContact(); Result: (A new Event record is created, and the Event's Primary Record Id value is set. If necessary, a new Monitor record is created. )
|
EventLogger getCurrentEventLogger(String newMonitorName)
Attempts to return the closest EventLogger instance in the calling stack (e.g. defined in the calling method). Note: This method is helpful for "adding on" to an existing log with content from a called sub-method. EventLogger el = sightlane.Logging.getCurrentEventLogger('My New Monitor'); Result: (If an existing EventLogger is found, it is returned, and the newMontiorName is ignored. If no EventLoggers are found, a new EventLogger is returned with the supplied monitor name. )
|
EventLogger getCurrentEventLogger(String newMonitorName, Id newPrimaryRecordId)
Attempts to return the closest EventLogger instance in the calling stack (e.g. defined in the calling method). Note: This method is helpful for "adding on" to an existing log with content from a called sub-method. EventLogger el = sightlane.Logging.getCurrentEventLogger('My New Monitor', '0010W00002g5ENfQAM'); Result: (If an existing EventLogger is found, it is returned, and the supplied newPrimaryRecordId is ignored. If no EventLoggers are found, a new EventLogger is returned with the supplied monitor name and associated with the supplied primary record. )
|
void reportToSightLane(String monitorName, String logStatement) Creates a new Event instance and reports it to SightLane in a "One-Liner" EventLogger el = sightlane.Logging.reportToSightLane('My New Monitor', 'This is a log statement'); Result: 2021-08-02 18:25:30 | This is my statement
|
void reportFailureToSightLane(String monitorName, String logStatement) Creates a new Event instance and reports it to SightLane in a "One-Liner" EventLogger el = sightlane.Logging.reportFailureToSightLane('My New Monitor', 'This is a log statement'); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement
|
void reportFailureToSightLane(String monitorName, String logStatement, Exception e) Creates a new Event instance and reports it to SightLane in a "One-Liner" try{ Result: (Event is created with a 'Failed' status and the exception stack trace is recorded) 2021-08-02 18:25:30 | This is my statement [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0
|
void reportToSightLane(String monitorName, List<String> logStatements) Creates a new Event instance and reports it to SightLane in a "One-Liner" Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void reportFailureToSightLane(String monitorName, List<String> logStatements) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void reportFailureToSightLane(String monitorName, List<String logStatements, Exception e) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
void reportToSightLane(String monitorName, String logStatement, SObject record) Creates a new Event instance and reports it to SightLane in a "One-Liner" Contact con = new Contact(FirstName='Bill', LastName='Johnson'); Result: 2021-08-02 18:25:30 | These are the Contact details 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson
|
void reportFailureToSightLane(String monitorName, String logStatement, SObject record) Creates a new Event instance and reports it to SightLane in a "One-Liner" Contact con = new Contact(FirstName='Bill', LastName='Johnson'); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | These are the Contact details 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson
|
void reportFailureToSightLane(String monitorName, String logStatement, Exception e, SObject record) Creates a new Event instance and reports it to SightLane in a "One-Liner" try{ Result: (Event is created with a 'Failed' status and the exception stack trace is recorded) 2021-08-02 18:25:30 | Error on Contact [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson
|
void reportToSightLane(String monitorName, List<String> logStatements, SObject record) Creates a new Event instance and reports it to SightLane in a "One-Liner" Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson |
void reportFailureToSightLane(String monitorName, List<String> logStatements, SObject record) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson |
void reportFailureToSightLane(String monitorName, List<String logStatements, Exception e, SObject record) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>(); Result: (Event is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement [SightLane Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 2021-08-02 18:25:30 | FirstName - Bill 2021-08-02 18:25:30 | LastName - Johnson |
Comments
Please sign in to leave a comment.