Log

This class is used for logging to standard outputs.

Contents

classdef Log
    % This defines the Log class.

    %   URL : $URL: $
    %   Log : $Id: Log.html,v 1.1 2008/07/23 12:51:19 jberg Exp $
    %   Copyright (c) 2008 The MathWorks, Inc.

Class Properties

    properties ( SetAccess = 'private', GetAccess = 'public', Constant = true )
        enabled = true;
        filename = fullfile(bb_root,'Temp','temp.log');
    end

    methods ( Static = true )

Public Static HELPER Methods

        function msg(str)
            if Log.enabled
                fid = Log.get_fid;
                fprintf(fid,['\n' str]);
                if (fid > 2)
                    fclose(fid);
                end
            end
        end

        function fid = get_fid()
            fid = fopen(Log.filename,'a');
            if (fid == -1) % Check that directory exists
                pathname = fileparts(Log.filename);
                if ~exist(pathname,'dir')
                    mkdir(pathname)
                end
                fid = fopen(Log.filename,'a');
                if (fid == -1)  % do we have write access?
                    fid = 1; % Standard Output
                end
            end
        end
    end
end