Logging
import logging
=logging.INFO)
logging.basicConfig(level
"This is a DEBUG message")
logging.debug("This is an INFO message")
logging.info("This is a WARNING message")
logging.warning("This is an ERROR message")
logging.error("This is a CRITICAL message") logging.critical(
One can add handlers so one log even can be handled in multiple ways, for example FileHandler stores to SDD:
= logging.FileHandler('myclass1.log')
handler
handler.setLevel(logging.INFO)self.logger.addHandler(handler)
self.logger.setLevel(logging.INFO)
Finally one can also parse log using grep:
grep "ERROR" your_log_file.log > errors_only.log
grep "^W" your_log_file.log > warnings.log
# to get every 100th line of file x.txt
awk 'NR % 100 == 0' x.txt > y.txt