Skip to content

Logging

It is possible for a driver support plugin to write information into the app logs, and consequently, Delphix Masking Engine logs. This is accomplished by using calling the getLogService method of the ServiceProvider interface provided at the driver support setup. The resulting LogService object may be used to make logging entries at various levels of severity. The available log levels are ERROR, WARNING, INFO, and DEBUG.

The log interface is provided to allow for debugging output during driver support development, and for reporting of statistical or similar values detailing the overall operation of the driver support, typically in the tearDown method.

Logging Verbosity

Driver support tasks also should not log progress messages or other verbose details, especially from the preJobExecute or postJobExecute methods, as this will fill the log files with messages and may impact job performance. There is a rate-limiting mechanism that limits the volume of messages each driver support can write over time, but any amount of routine logging is likely to diminish the overall usefulness of the logs by obscuring more important messages.

Example Code

This example is take from the MSSQL sample Disable Constraints driver support task provided with the SDK:

public class DisableConstraints implements Task {
    ...
    private LogService logService;
    ...

    @Override
    public String getTaskName() {
        return "Disable Constraints";
    }

    @Override
    public void setup(ComponentService serviceProvider) {
        this.jobInfo = serviceProvider.getJobInfo();
        this.targetConnection = serviceProvider.getTargetConnection();
        this.logService = serviceProvider.getLogService();
    }

    ...

    @Override
    public void preJobExecute() throws MaskingException {
        long start = System.currentTimeMillis();
        disableConstraints();
        logService.info(
                String.format(
                        "Total execution to disable all constraints on masked tables took %s ms.",
                        String.valueOf(System.currentTimeMillis() - start)));
    }

    /** This function enables all constraints on the target database table. */
    private void disableConstraints() throws MaskingException {
        this.enabledConstraints = findEnabledConstraints();
        try (Statement statement = targetConnection.createStatement()) {
            for (ConstraintMetadata constraint : enabledConstraints.values()) {
                logService.info(
                        String.format(
                                "Starting to disable constraint: \"%s\" on table \"%s\"",
                                constraint.getName(), constraint.getQualifiedTableName()));
                try {
                    String builtSqlStatement =
                            String.format(
                                    ALTER_CONSTRAINT_STATEMENT,
                                    constraint.getQualifiedTableName(),
                                    constraint.getDisableAction(),
                                    constraint.getName(),
                                    ";");
                    logService.info(builtSqlStatement);
                    statement.execute(builtSqlStatement);
                } catch (SQLException e) {
                    String errorMessage =
                            String.format(
                                    "Error disabling constraint: \"%s\" on table \"%s\".",
                                    constraint.getName(), constraint.getQualifiedTableName());
                    logService.error(errorMessage + e);
                    throw new MaskingException(errorMessage, e);
                }
                logService.info(
                        String.format(
                                "Finished disabling constraint: \"%s\" on table \"%s\".",
                                constraint.getName(), constraint.getQualifiedTableName()));
            }
        } catch (SQLException e) {
            String errorMessage =
                    String.format(
                            "Error creating statement on target connection %s: ",
                            targetConnection.getClass());
            logService.error(errorMessage + e);
            throw new MaskingException(errorMessage, e);
        }
    }
    ...

    @Override
    public void postJobExecute() throws MaskingException {
        long start = System.currentTimeMillis();
        enableConstraints(); // comment this out if testing of the task execution via the SDK is desired
        logService.info(
                String.format(
                        "Total execution to enable all constraints on masked tables took %s ms.",
                        System.currentTimeMillis() - start));
    }

Many methods and fields elided for the sake of brevity

The relevant details here:

  • The setup method uses the provided ComponentService object to get a LogService instance, saving it as logService.
  • The disableConstraints method calls the logger's info method to write informational messages at random during execution. This kind of "progress" logging may be useful during development but should be removed for driver supports before production deployment. It also calls the logger's error method in the event of a failure to connect to the data source or otherwise execute the task on the given data source.