Logging

import logging

logging.basicConfig(level=logging.INFO)

logging.debug("This is a DEBUG message")
logging.info("This is an INFO message")
logging.warning("This is a WARNING message")
logging.error("This is an ERROR message")
logging.critical("This is a CRITICAL message")

One can add handlers so one log even can be handled in multiple ways, for example FileHandler stores to SDD:

handler = logging.FileHandler('myclass1.log')
            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