function [value, flagName] = getWorkerDebugSetting()
% getWorkerDebugSetting - get the value of the worker debug flag
%
% Returns the value of the debug flag from the system environment
% as a character vector, or an empty char if it is not set.
% Also returns the name of the environment variable that was found.

%   Copyright 2018 The MathWorks, Inc.

flagName = '';
% In R2019a PARALLEL_SERVER_DEBUG was added as the default debug
% flag. MDCE_DEBUG remains for compatibility.
debugFlagNames = ["PARALLEL_SERVER_DEBUG", "MDCE_DEBUG"];
for thisName = debugFlagNames
    value = getenv(thisName);
    if ~isempty(value)
        flagName = char(thisName);
        % Return as soon as we match a debug flag since
        % only one should be set at a time.
        return
    end
end
