Code covered by the BSD License  

Highlights from
log4matlab

Be the first to rate this file! 10 Downloads (last 30 days) File Size: 6.75 KB File ID: #33532

log4matlab

by Gavin

 

29 Oct 2011 (Updated 22 Nov 2011)

Simple logger written with log4cxx in mind

| Watch this File

File Information
Description

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.

Required Products MATLAB
MATLAB release MATLAB 7.11 (2010b)
Other requirements Written in winXP, tested on matlab 2010b/2009a. Also tested in Linux: MATLAB 2011a
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
22 Nov 2011 Yair Altman

Gavin - I had a log4m implementation in my TODO list for many months - Good for you for doing it faster than me!

Please login to add a comment or rating.
Updates
01 Nov 2011

- support for namespaces. identifiers with namespaces are setable/gettable
- namespace class example
- example script implementing documented functions so runable
- singleInstance singleton class as a good way to use log4matlab in a large project

01 Nov 2011

- I forgot to upload the new file yesterday corresponding to the the changes I said I made.

01 Nov 2011

- got rid of the hidden SVN folders inside the zip file submitted

22 Nov 2011

- Fixed bug with appender not called early enough in constructor
- Added method setCommandWindowLevel so user can set the level of console output for DEBUG/WARN/ERROR messages.
- Added test cases and documentation for changes

Tag Activity for this File
Tag Applied By Date/Time
logging to file Gavin 31 Oct 2011 16:03:38
logger Gavin 31 Oct 2011 16:03:38
log4cxx Gavin 31 Oct 2011 16:03:38
project management Gavin 31 Oct 2011 16:03:38
save errors Gavin 31 Oct 2011 16:03:38
debug messages Gavin 31 Oct 2011 16:03:38
debugging Gavin 31 Oct 2011 16:03:38
error checking Gavin 31 Oct 2011 16:03:38
debug Gavin 31 Oct 2011 16:03:38
class debugging Gavin 01 Nov 2011 11:33:39

Contact us at files@mathworks.com