A minimalistic class I mostly use in Python scripts to log output in a shell. It is compatible with Python 2.7 and 3.x. It can easily be customized to fit ones needs.
There are multiple ways to use/install this modules:
- Just copy
tinylogs.pyinto your project folder. - Run
python setup.py installto installtinylogsinto your globalsite-packagesdirectory.
from tinylogs import TinyLogs
if __name__ == '__main__':
# Create a log instance (with debug output)
log = TinyLogs(debug=True)
# Log some info
log.info('Starting code flow')
# Log some debug information
log.debug('A fancy debug message')
if True:
# Log a warning
log.warn('Not good, but everything is still OK.')
if True:
# Log an error. Error logs and exits.
log.error('Encountered an error, exiting.')from tinylogs import TinyLogs
if __name__ == '__main__':
# Create a log instance that logs into a logfile. multi indicates that
# logs should be written into a file and additionally printed stdout.
log = TinyLogs(file='/tmp/logfile', multi=True)
# Log some info
log.info('Starting code flow')
# Log some debug information
log.debug('A fancy debug message')
if True:
# Log a warning
log.warn('Not good, but everything is still OK.')
if True:
# Log an error. Error logs and exits.
log.error('Encountered an error, exiting.')