Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Python logging to html

Project description

Support both Python2 and Python3

PyLog2Html can save log to HTML file, there is plenty of reasons to save log into HTML file:

  • Highlight errors
  • Colorful output
  • More readable
  • Insert table


Install with pip:

pip install PyLog2html

Quick Start

from HTMLLogger import HTMLLogger
logger=HTMLLogger(name="Test App", html_filename="log.html", console_log=True)'This is info')
logger.debug('This is debug')
logger.warning("This is <hl>warning</hl>")
logger.error('This is an <hl>error</hl>')
logger.table('Add html table:<table><tr><th>...</th></tr></table>')

View the log:

  • Open log file “log.html” in browser, it takes a while to open the log file, it depends on the performance of your computer.
  • Select a level name to dedicate on particular messages.
  • Or type a keyword to find your interesting message(select checkbox to mismatch case)
  • If you set console_log to True when you’ll see the log would also print to console



Class Inheritance:

  • [HTMLFileHandler]: The derived class of Python logging.handlers.RotatingFileHandler
  • [HTMLFormatter]: The derived class of Python logging.Formatter
  • [CONFormatter]: The derived class of Python logging.Formatter


The sub class of logging.handlers.RotatingFileHandler, you can see this class is to extend the function of Rotating HTML file, comparing to its parent class, it has following advantages:

  • The format of log file name will be saved as “log_1.html” & “log_2.html”.
  • Write the beginning and end strings in HTML, like “<html><head>…</head></html>”
  • Have a switch to let user choose if need to rotate files: If it’s False, the log file will be added and rollover occurs whenever the current log file is nearly maxBytes in length. If it’s True, it behaves like logging.handlers.RotatingFileHandler.


The sub class of logging.Formatter, you can see this class is to add HTML tags, comparing to its parent class, it has following advantages:

  • Highlight keyword by setting its size and the Italic
  • Find the correct color to display for particular messages in Html file.
  • The keyword should be decorated by <hl>keyword</hl>(which can be found in config file or variables you defined.)


The sub class of logging.Formatter, this module is to print log to console with color if console_log was set to True when you instance class PyLogger and raise errors if the color you chose is not supported by Console.

Currently, Only following color are supported in Console:

  • yellow
  • cyan
  • magenta
  • blue
  • orange
  • green
  • red
  • black
  • white
  • normal


The main logger creator, the sub class of logging.Logger, use to instance a single logging channel. By default, you should use this class rather than use logging.Logger. If you’d like to create a logger with the specified name, you should call function <logging.getLogger> and add HTMLFormatter and HTMLFileHandler using addFilter and addHandler.

The config

You have two options here:

  • Use oslo.config , and read variables from the config file
  • Set Variables in your script.

An example:

from HTMLLogger import HTMLLogger

log_format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
html_title="Default Title"

logger=PyLogger(name=app_name, html_filename=html_filename, mode='a',
HtmlmaxBytes=HtmlmaxBytes, encoding=None, delay=False,
html_format=log_format, msg_color=msg_color,

logger.debug('This is debug')'This is info')
logger.warning("This is <hl>warning</hl>")
logger.error('This is <hl>error</hl> xxx')
logger.table('Add html table:<table><tr><th>...</th></tr></table>')

Free Software, Hell Yeah!

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
PyLog2html-1.0.4.tar.gz (10.0 kB) Copy SHA256 hash SHA256 Source None Oct 14, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page