This has been a very useful tool for me for logging from multiple classes/functions. Writing log messages to command line is not scalable for large projects with many classes. I wrote this because I log4cxx is awesome and I wanted something for matlab that could be used easily log to file so I could debug.
If the logger is made a singleton for a project then all classes can write their log messages to the same file.
Supports Debug messages, warning messages and error messages.
Logs to the time in milliseconds when the message was sent
In order to set the file with which to log to
L = log4matlab('logFileName.log');
--
To log a debug message about a class called 'myClassName'
L.mlog = {L.DEBUG,'myClassName','This is a debug message'};
--
To log a warning message about a function called 'SomeFunction'
L.mlog = {L.WARN,'SomeFunction','This is a warning message'};
--
To log an error message about a script called 'ThisIsArbitrary'
L.mlog = {L.ERROR,'ThisIsArbitrary','This is an error message'};
--
To set the logger level for class called 'myClassName' so that only warnings and errors are shown.
Then to send 3 log messages of which only 2 will now be logged
L.setLoggerLevel('myClassName',L.WARN)
L.mlog = {L.DEBUG,'myClassName','This is a debug message'};
L.mlog = {L.WARN,'myClassName','This is a warning message'};
L.mlog = {L.ERROR,'myClassName','This is an error message'};
--
To set the logger level for function called 'SomeFunction' so that only errors are shown.
Then to send 3 log messages of which only 1 will now be logged
L.setLoggerLevel('SomeFunction',L.ERROR)
L.mlog = {L.DEBUG,'SomeFunction','This is a debug message'};
L.mlog = {L.WARN,'SomeFunction','This is a warning message'};
L.mlog = {L.ERROR,'SomeFunction','This is an error message'};
--
To get the logger level for myClassName, SomeFunction and ThisIsArbitrary and see they are equal to what we expect
L.getLoggerLevel('myClassName') == L.WARN
L.getLoggerLevel('SomeFunction') == L.ERROR
L.getLoggerLevel('ThisIsArbitrary') == L.DEBUG
--
Start with the 'Example.m' script that shows how to use log4matlab as a script and also how to use it in a project containing multiple classes and classes in namespaces.
NOT NECESSRY BUT as an additional extra, if you wish to run the unit test cases file log4matlabTestCase.m you need the sourceforge project: mlUnit - Testing Framework for MATLAB (http://sourceforge.net/projects/mlunit/). You DO NOT NEED THIS. |