How to do logging in matlab : anything similar to logging like python

Viewed 691

I am new to matlab:

I was working in python, I generally use logging a lot to keep track of the code. In python, we can use below

import logging
logger = logging.getlogger()
logger.setLevel(logging.INFO)
handler = logging.FileHandler("log.txt",mode=w+)
handler.setlevel(loggin.INFO)
logger.addHandler(handler)

#And any where in the code use it as

logger.info("testing")

How can we do something similar in matlab

1 Answers

There's no built-in logging feature in Matlab. So you need to use third-party or undocumented tools.

Matlab ships the Java logging libraries SLF4J and log4j with its bundled JVM. You can make use of them for your logging. There's a Matlab SLF4M library that provides a layer of convenient Matlab bindings for SLF4J/log4j. (Full disclosure: I wrote SLF4M.)

There are also some native M-code Matlab logging libraries available on the MathWorks File Exchange:

Related