A minimalistic logger for your Salesforce Apex code.
Logger.LogSeverity- an enum containing message severity types:INFO,SUCCESS,ERRORandDEBUG.
static void log(Logger.LogSeverity severity, String message)- a generic method for logging a message with a specific severity.static void logInfo(String message)- a method for logging a message with the predefinedINFOseverity.static void logSuccess(String message)- a method for logging a message with the predefinedSUCCESSseverity.static void logError(String message)- a method for logging a message with the predefinedERRORseverity.static void commitLogs()- a method for committing logs to database if any.
You can log different kind of messages using logError, logSuccess or logInfo methods, also it is possible to construct your own log message using a generic log method:
Logger.logError('Test Error message');
Logger.logSuccess('Test Success message');
Logger.logInfo('Test Info message');
Logger.log(Logger.LogSeverity.DEBUG, 'Test Debug message');Dont forget to call commitLogs method in the end of your execution context or another suitable place:
Logger.commitLogs();The typical usage of logger is in try...catch...finally blocks:
try {
// Some glitchy code
throw new NullPointerException('error message');
} catch (Exception ex) {
Logger.logError(ex.getMessage());
} finally {
Logger.commitLogs();
}- For the convenience of usage and determining the logging events was included a hierarchy custom setting support:
- Go the the Setup -> Custom Settings -> Logger Config
- Define a default logging behavior using org-wide custom setting values.
- In case of a specific user or profile should be logged create a custom setting record for them and define a logging level using the checkboxes.
- You can integrate the logger switch in any other suitable way.
The MIT License (MIT). Please see License File for more information.