A simple but powerful logging framework for Matlab
SLF4M is a simple but flexible logging framework for Matlab, built on top of SLF4J and Apache Log4j. You can use it to do runtime-configurable logging from your Matlab scripts and programs. This can be more informative and more manageable than commenting `fprintf()` statements in and out.
* Logging functions
* A `dispstr` API for customizing object display.
* A Log4j configuration GUI
The API is simple enough that you can get up and running with it quickly, or even use it casually in scripts, but it's flexible and powerful enough to be useful for larger systems.
The logging functions are in the `+logger` package. Call them from within your Matlab code.
if nargin < 1 || isempty(x)
x = 123.456;
% These debug() calls will only show up if you set log level to DEBUG
logger.debug('Got empty x input; defaulted to %f', x);
z = x + 42;
timestamp = datetime;
logger.info('Answer: z=%f, calculated at %s', z, timestamp);
if z > intmax('int32')
logger.warn('Large value z=%f will overflow int32', z);
logger.error(err, 'Something went wrong in some_bad_operation(x=%f)');
The output looks like this:
06:39:45.292 INFO helloWorld - Answer: z=165.456000, calculated at 09-Jan-2020 06:39:45
06:39:45.297 ERROR helloWorld - Something went wrong in some_bad_operation(123.456000)
Undefined function 'some_bad_operation' for input arguments of type 'double'.
Error in helloWorld (line 16)
Thanks to `dispstr()`, you can also pass Matlab objects to the `%s` conversions.
>> m = containers.Map;
>> m('foo') = 42; m('bar') = struct;
>> logger.info('Hello, world! %s', m)
09:52:29.809 INFO base - Hello, world! 2-by-1 containers.Map
For more details, see the User's Guide included in the distribution.
SLF4M is developed by Andrew Janke <firstname.lastname@example.org>.
SLF4M's home page is the repo on GitHub: https://github.com/apjanke/SLF4M.
Andrew Janke (2021). SLF4M (https://github.com/janklab/SLF4M/releases/tag/v1.3.0), GitHub. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!