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();
인용 양식
Matthew Spaethe (2024). Matlab logging facility (https://www.mathworks.com/matlabcentral/fileexchange/42078-matlab-logging-facility), MATLAB Central File Exchange. 검색 날짜: .
MATLAB 릴리스 호환 정보
플랫폼 호환성
Windows macOS Linux카테고리
- MATLAB > Programming > Functions > Scope Variables and Generate Names >
- MATLAB > External Language Interfaces > Python with MATLAB > Call Python from MATLAB >
태그
도움
도움 받은 파일: Design Pattern: Singleton (Creational)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!+logging/
버전 | 게시됨 | 릴리스 정보 | |
---|---|---|---|
1.0.0.0 |