textOut

Wrapper for fprintf() which can optionally write screen output to a logfile

Contents

Syntax

textOut(strMsg)

textOut(strMsg, 'screenonly')

textOut(strMsg, 'logonly')

Description

textOut(strMsg) will write to screen (command window) AND logfile, if global logging is enabled.

textOut(strMsg, 'screenonly') writes to screen (command window) only.

textOut(strMsg, 'logonly') writes to logfile only (global logging must be enabled). If logging is disabled or somehow failes, the message will not be logged or displayed at all...

Note:

To enable logging (to file), set the global var EnableLogging to true and set Logfilename to a valid filename. This function distinguishes between Windows and Linux systems to use proper linebreaks. The global variable DisableScreenOut is an on/off switch for the complete textOut()-messages that would appear on the command window. Default setting is false, i.e. there will be no output.

Recommended usage is together with sprintf(), in order to add linebreaks for example.

Examples

  textOut('This is a message\n');
  x = 'world';
  y = 2007;
  textOut(sprintf('Hello %s, it is the year %d!\n', x, y));
  %Results in:  >> Hello world, it is the year 2007!
  global EnableLogging
  global Logfilename
  EnableLogging = true;
  Logfilename = 'logfile.txt';
  textOut(sprintf('Whatever I say here will be logged to the file as well.\n'));
  textOut(sprintf('Only appears in the command window\n'), 'screenonly');
  textOut(sprintf('Only appears in the logfile, if logging enabled\n'), 'logonly');
  global DisableScreenOut
  DisableScreenOut = true;
  textOut(sprintf(['If logging is enabled, this goes to the logfile, ', ...
                   'if not, this goes nowhere\n']));

See also

DebugMode, isdebug (private),

Signature