Message Logger

Message logger with font formats, timestamp, auto save, verbose, graphical interface, inheritance...
75 Downloads
Updated Sun, 12 Mar 2017 14:32:34 +0000

View License

Message Logger objects to automatically store messages with or without formatting and timestamp.
Objects (MCV):
- logModel
- logController
- logView

LogModel: Stores all messages and their properties (color, size, style, etc).
LogController: Interface between the model and the view. Use it to create a graphical interface.
LogView: Graphical user interface to show the messages with their properties in a scrollable listbox.

As for the standard MCV architecture the model can be used with or without the view. Normal use:
mainLog = logger.logModel % Creates the log
logCont = logger.logController(mainLog) % Creates the GUI for the expecified logger

Capabilities of logModel include:
- Font formatting independent for each line. The text will show the selected formatting when using the view gui or when exporting to HTML. Valid formats include color, size, font types ('Arial', 'Comic Sans MS', 'Courier', 'Impact', 'Times New Roman', 'Verdana') and styles ('Bold', 'Italic', 'mark', 'emphasized', 'subscript', 'superscript'). A list of pre-defined colors is available by typing 'logger.getcolorlist'.
- Automatic saving of the logs into a file (txt or HTML). An output file can be defined at any moment and all new messages will be stored in the file. Until this option is disabled again (by defining an empty string) the output file shouldn't be open by any software that locks the access to the file, like MS Office or any new message won't be stored in the file.
- Automatic generation of a timestamp to be applied at the formated messages. By default this property is enabled.
- Capability of assingning a 'defcon' level to the message from 1 to 6. Usually 1 being an error, 2 a warning and 3 to 6 user defined levels. By default level 1 will be asigned color red and level 2 will be asigned orange unless the user specifies a different colorSet.
- Export the log to: clipboard, txt file or HTML file.
- Filter the log per timestamp, properties, text or defcon level.
- Inheritance among logger objects. It is possible to create multiple objects to track different messages and define a main or parent logger that will receive all messages from the other loggers. Each object will keep track or its own messages. A view can be assigned to each one of the loggers or to the main one.
- Verbose mode. Automatically print any new message to the command line. Default set as false.

This toolbox was developed by Jose del Rio

External thanks to the developer of the external libraries used in this package (see licenses):
- colornames by Stephen Cobeldick. Used by the model. It's optional but it is nicer to have a list of colors instead of RGB numbers.
- GUI Layout Toolbox by David Sampson. Used in the view.
- findobj tool by Yair Altman. Used in the view.

Examples:

% Logger created with default values
mainLog = logger.logModel

% Logger with some parameters (log lines with timestamp, auto saving log into a file, verbose to the command line...)
mainlog = logger.logModel('default_defcon', 3, 'flag_timestamp', false, 'log_file', '2017-03-11_log.txt', 'verbose', true)

% Create secondary log
secondary_log1 = logger.logModel
secondary_log2 = logger.logModel

% Link all messages of the secondary_logs to the main logger
mainLog.addChild(secondary_log1)
mainLog.addChild(secondary_log2)

% Create some views at any moment from any logger
viewMain = logger.logController(mainLog)
viewSec1 = logger.logController(secondary_log1)
...

% Add new entries...
mainLog.newEntry('Hello') % Entry with default properties: 2017-03-05 10:32:48 >> Hello
mainLog.newEntry('This is an error', 'defcon', 1) % Entry with color as defined for level 1
mainLog.newEntry('This is other error', 'defcon', 1, 'prop', 'yellow') % Entry of level 1 with overwritten color property

% Entry with multiple lines and multiple properties ('Bold', 'Italic', 'mark', 'emphasized', 'subscript', 'superscript' will be shown correctly in the html file)
multiline = sprintf('Multiple lines\nin single entry')
mainLog.newEntry( multiline, 'prop', {'Light Blue', 3, 'Bold', 'Comic Sans MS'})

% To store some value
mainLog.newParam(myvalue, 'name', 'version')
Please feel free to send any suggestions

Cite As

Jose Del Rio (2024). Message Logger (https://www.mathworks.com/matlabcentral/fileexchange/61999-message-logger), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.3

Added the store of parameters

1.0.2.0

Added documentation and minor fixes

1.0.1.0

Cleaner install