Matlab logging facility
The Logger class is used for logging messages. The logger instances are named, and they are managed by LogManager.
The logger instance will compare the logging level of the message to its logging level. If the message's logging level meets or exceeds the logging level of the logger, the log message will be passed to its registered handlers. By default, the log message will also then be passed to its parent's handlers.
Handlers are what "emit" the log message to the outside world. Loggers decide if the log message should be seen by the Handlers.
The logging classes are in a Matlab package 'logging'. You will need to place the +logging directoy somewhere in your path. That is, the directory where the +logging directoy exists should be in your Matlab path -- not the +logging directory itself.
I would suggest doing a Google on java logging and reading a bit about Logger and LogManager. I think it may do a better job of trying to explain :).
Example code:
import logging.*
% --- BASIC CONSOLE ---
% get the global LogManager
logManager = LogManager.getLogManager();
% add a logger instance to this script
logger = Logger.getLogger('TestScript');
logger.setLevel( Level.ALL );
logger.info('Hi, this is info!');
logger.warning('Hi, this is warning!');
% side-effect is to close all handlers
logManager.resetAll();
% --- BASIC CONSOLE WITH FILE ---
% get the global LogManager
logManager = LogManager.getLogManager();
% add a file handler to the root logger
fileHandler = FileHandler('./Basic-RootFileHandler.log');
fileHandler.setLevel( Level.ALL );
rootLogger = logManager.getLogger('');
rootLogger.addHandler( fileHandler );
% add a logger instance to this script
% will use stack to generate name for logger since a name is not being provided
logger = Logger.getLogger( );
logger.setLevel( Level.ALL );
logger.info('Hi, this is info!');
logger.warning('Hi, this is warning!');
% side-effect is to close all handlers
logManager.resetAll();
Zitieren als
Matthew Spaethe (2024). Matlab logging facility (https://www.mathworks.com/matlabcentral/fileexchange/42078-matlab-logging-facility), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
- MATLAB > Programming > Functions > Scope Variables and Generate Names >
- MATLAB > External Language Interfaces > Python with MATLAB > Call Python from MATLAB >
Tags
Quellenangaben
Inspiriert von: Design Pattern: Singleton (Creational)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
+logging/
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0.0 |