function setModelLoggingInfo(obj)
%

%   Copyright 2011-2021 The MathWorks, Inc.

    topLevelModelH = obj.ModelHsInMdlRefTree(1);
    mi = Simulink.SimulationData.ModelLoggingInfo(get_param(topLevelModelH,'Name'));
    mi.LoggingMode = 'OverrideSignals';
    
    numPorts = length(obj.PortHsToLog);
    if ~isempty(obj.ModelBlockH)
        % Get a model path as cell array
        portBlockPathPrefix = obj.ModelBlockPath.convertToCell;

        for idx=1:numPorts
            % Append port path to model block path cell array to construct
            % block path for port
            portBlockPath = vertcat(portBlockPathPrefix, ...
                getfullname(get_param(obj.PortHsToLog(idx),'Parent')));
            
            % Set signal logging info. This enables logging ports for only specified block path context
            mi.Signals(idx) = Simulink.SimulationData.SignalLoggingInfo(portBlockPath);
        end
        
    else
        convBlock = getfullname(obj.ConvBlockH);        
        for idx=1:numPorts
            mi.Signals(idx) = Simulink.SimulationData.SignalLoggingInfo(convBlock,idx);
        end        
    end
    
    for idx=1:numPorts        
        mi.Signals(idx).LoggingInfo.NameMode = true;
        mi.Signals(idx).LoggingInfo.LoggingName = sprintf('%s%d',obj.SignalLoggerPrefix, idx);
    end
    
    set_param(topLevelModelH, 'DataLoggingOverride', mi);
    set_param(topLevelModelH, 'LoggingToFile', 'off');
end
