Created
October 29, 2013 03:20
-
-
Save kyamagu/7208738 to your computer and use it in GitHub Desktop.
Display a log message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logger( varargin ) | |
%LOGGER Display a log message. | |
% | |
% logger(fmt, param1, param2, ...) | |
% logger(true) | |
% logger(false) | |
% | |
% LOGGER displays a log message using the printf arguments. LOGGER takes | |
% format string FMT followed by parameters for substituion. | |
% | |
% LOGGER can be turned on/off by passing scalar logical value. This is | |
% useful in controling verbosity of the display text. | |
% | |
% logger('INFO: The value is %d', 42) | |
% | |
% See also fprintf disp | |
persistent enabled; | |
if isempty(enabled) | |
enabled = true; | |
end | |
if nargin == 1 && islogical(varargin{1}) && isscalar(varargin{1}) | |
enabled = varargin{1}; | |
elseif enabled | |
fprintf('[%s] ', datestr(now)); | |
fprintf(varargin{:}); | |
fprintf('\n'); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment