Matlab logging facility

버전 1.0.0.0 (12.2 KB) 작성자: Matthew Spaethe
Adds ability to log messages. Borrowed ideas from Java logging, and possibly Python logging.
다운로드 수: 776
업데이트 날짜: 2013/6/3

라이선스 보기

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 릴리스 호환 정보
개발 환경: R2012a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Scope Variables and Generate Names에 대해 자세히 알아보기
태그 태그 추가
도움

도움 받은 파일: Design Pattern: Singleton (Creational)

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0