function setModelLoggingInfo(obj)
%

%   Copyright 2011-2023 The MathWorks, Inc.

    topLevelModelH = obj.ModelHsInMdlRefTree(1);
    mi = Simulink.SimulationData.ModelLoggingInfo(get_param(topLevelModelH,'Name'));
    mi.LoggingMode = 'OverrideSignals';
    
    numPorts = length(obj.PortHsToLog);
    numGlobals = length(obj.subsystemIO.globalVarInfo);
    fullModelBlockPath = getfullname(obj.ModelBlockH);
    for idx=1:numPorts
        mi.Signals(idx) = ...
            Simulink.SimulationData.SignalLoggingInfo(...
            {fullModelBlockPath,...
            getfullname(get_param(obj.PortHsToLog(idx),'Parent'))});
    end
    
    
    for idx=1:numPorts        
        mi.Signals(idx).LoggingInfo.NameMode = true;
        mi.Signals(idx).LoggingInfo.LoggingName = sprintf('%s%d',obj.SignalLoggerPrefix, idx);
    end
    for i = 1:numGlobals
        sigName = obj.subsystemIO.globalVarInfo{i}.SignalName;
        % Fetch signal object from global context, turn on DataLogging
        % and write back.
        signal = getVarFromGlobalScope(obj.TopLevelModelH, sigName);
        signal.LoggingInfo.DataLogging = true;
        assigninGlobalScope(obj.TopLevelModelH, sigName, signal);
    end
    
    set_param(topLevelModelH, 'DataLoggingOverride', mi);
    set_param(topLevelModelH, 'LoggingToFile', 'off');
end
