unsplit icon indicating copy to clipboard operation
unsplit copied to clipboard

Added the ability to plug in a log function

Open alexthornton1 opened this issue 12 years ago • 0 comments

Added the ability to plug in a log function in place of the existing calls to io:fwrite and error_logger:format. The details are as follows:

(1) Added two new types to unsplit.hrl:

* log_type(), which is either the atom 'normal' or the atom 'error'.
  Each log message has one type or the other.
* log_fun(), which is the kind of fun that writes log messages.  It
  takes two arguments: a log_type() and a string().

(2) Added a key 'log_fun' to the {unsplit, ...} application environment variable in unsplit.app.src. Its value is a tuple {Module, FunctionName}.

(3) Added a function unsplit:default_log_fun, which is what it sounds like: the default log_fun when none is explicitly specified. It writes normal messages using io:fwrite and error messages using error_logger:format, mirroring previous functionality.

(4) Added three overloads of a function unsplit:log_write, which writes messages (with or without formatting) to whatever log function has been configured in the {unsplit, ...} application environment variable.

(5) Added a function unsplit:get_logger, which builds a fun that calls the appropriate log_fun.

(6) Replaced all explicit calls to io:fwrite(...) with calls to unsplit:log_write(normal, ...) instead.

(7) Replaced all explicit calls to error_logger:format(...) with calls to unsplit:log_write(error, ...) instead.

(8) Regenerated unsplit.md documentation file.

When the new 'log_fun' application environment variable has its default value, unsplit behaves as it did before. However, logging functionality can now be plugged in to replace the existing functionality.

alexthornton1 avatar Jan 03 '13 08:01 alexthornton1