Skip to content

Instantly share code, notes, and snippets.

@kyamagu
Created October 29, 2013 03:20
Show Gist options
  • Save kyamagu/7208738 to your computer and use it in GitHub Desktop.
Save kyamagu/7208738 to your computer and use it in GitHub Desktop.
Display a log message.
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