VzLog

class vzlog.VzLog(path, name=None, file_rights=None, encoding='utf-8')

Logging class that manages an HTML log file. Mainly used for visually rich logging with plenty of images.

Parameters:
  • path – Path the directory where the files will be saved.
  • name – Specify name of the output document. This will be used to set the document title. Inferred from path if set to None.
clear()

Prepares a folder for logging. This also clears any previous output and can thus be used during an interactive session when wanting a clean slate.

flush()

Flushes the output. This mainly updates the file rights for newly added files. Normally, you do not need to call this yourself. However, it can be useful during an interactive session when the file rights have not be processed yet.

impath(ext='png', scale=1.0)

This generates a path to an image file, outputs the image and returns the path. Specify the extension with ext.

>>> from vzlog.default import vz

We can output an image by saving the file:

>>> ag.image.save(vz.impath(ext='png'), im)

Or with matplotlib using a vector format:

>>> import pylab as pl
>>> pl.figure()
>>> pl.plot([1,3,2,3,1])
>>> pl.savefig(vz.impath(ext='svg'))
Parameters:
  • ext – Extension of image file.
  • scale – Scale of image when viewed in the browser. This will use nearest neighbor upscaling that works well with pixel grids (if your browser supports it).
items(items, style='bullets')

Outputs an item list.

Parameters:
  • items – Iterable of representable objects. If an item is a list, it will call itself recursively.
  • style – List style: 'bullets' or 'numbers'. Use a list/tuple of values if you want different levels to have different styles.
log(*args, **kwargs)

Logs text with mono-spaced font (<pre>). This function and many other text outputting functions uses the same arguments as the built-in print function. The only difference is that will ignore file if specified.

>>> vz.log('Logging a value', 100)
output(obj)

Outputs an object. This will look for obj._vzlog_output_ and pass itself along as the only argument. If the object does not have such a function, it will fall back to calling VzLog.log.

output_with_tag(tag, *args, **kwargs)

Outputs strings surrounded by a specific HTML tag.

savefig(fig=None)

Saves a matplotlib figure to the log file. This can also be done using impath, but this will save both a SVG and a PDF version. The SVG will be viewed directly in the browser next to a link to the PDF (so it can be downloaded).

Parameters:fig – If specified, this should a matplotlib figure object that fig.savefig will be called on.
section(*args, **kwargs)

Adds a section title (<h2>). See log for arguments.

text(*args, **kwargs)

Adds a paragraph of text (<p>). See log for arguments.

timed(*args, **kwds)

Context manager to make it easy to time the execution of a piece of code. This timer will never run your code several times and is meant for simple in-production timing, instead of benchmarking. It measure wall-clock time.

>>> with vz.timed('Sleep'):
...     time.sleep(1)
Parameters:name – Name of the timing block, to identify it.
title(*args, **kwargs)

Adds a title (<h1>). See log for arguments.