Skip to content

A minimalistic logger for your Salesforce Apex code. Fully covered with unit tests, quick deploy button added.

License

Notifications You must be signed in to change notification settings

AndreyFilonenko/sfdc-logger

Repository files navigation

Simple Salesforce Apex logger

CircleCI codecov

Deploy to Salesforce

Overview

A minimalistic logger for your Salesforce Apex code.

Usage

Logger public API

Enums:

  • Logger.LogSeverity - an enum containing message severity types: INFO, SUCCESS, ERROR and DEBUG.

Methods:

  • 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 predefined INFO severity.
  • static void logSuccess(String message) - a method for logging a message with the predefined SUCCESS severity.
  • static void logError(String message) - a method for logging a message with the predefined ERROR severity.
  • static void commitLogs() - a method for committing logs to database if any.

Logger methods usage

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

Configuration and feature enablement

  • For the convenience of usage and determining the logging events was included a hierarchy custom setting support:
    1. Go the the Setup -> Custom Settings -> Logger Config
    2. Define a default logging behavior using org-wide custom setting values.
    3. 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.

License

The MIT License (MIT). Please see License File for more information.

About

A minimalistic logger for your Salesforce Apex code. Fully covered with unit tests, quick deploy button added.

Topics

Resources

License

Stars

Watchers

Forks

Languages