Log

The log module provides print methods debug, info, user, warning, and error, in increasing order of priority. Output is sent to stdout as well as to an html formatted log file if so configured.

class nutils.log.Log[source]

Base class for log objects. A subclass should define a context() method that returns a context manager which adds a contextual layer and a write() method.

context(title)[source]

Return a context manager that adds a contextual layer named title.

Note

This function is abstract.

write(level, text)[source]

Write text with log level level to the log.

Note

This function is abstract.

class nutils.log.ContextLog[source]

Base class for loggers that keep track of the current list of contexts.

The base class implements context() which keeps the attribute _context up-to-date.

_context

A list of contexts (strs) that are currently active.

context(title)[source]

Return a context manager that adds a contextual layer named title.

The list of currently active contexts is stored in _context.

class nutils.log.ContextTreeLog[source]

Base class for loggers that display contexts as a tree.

_print_push_context(title)[source]

Push a context to the log.

This method is called just before the first item of this context is added to the log. If no items are added to the log within this context or children of this context this method nor _print_pop_context() will be called.

Note

This function is abstract.

_print_pop_context()[source]

Pop a context from the log.

This method is called whenever a context is exited, but only if _print_push_context() has been called before for the same context.

Note

This function is abstract.

_print_item(level, text)[source]

Add an item to the log.

Note

This function is abstract.

write(level, text)[source]

Write text with log level level to the log.

This method makes sure the current context is printed and calls _print_item().

class nutils.log.StdoutLog(stream=None)[source]

Output plain text to stream.

write(level, text, endl=True)[source]

Write text with log level level to the log.

Note

This function is abstract.

class nutils.log.RichOutputLog(stream=None, *, progressinterval=None)[source]

Output rich (colored,unicode) text to stream.

class nutils.log.HtmlInsertAnchor[source]

Mix-in class for HTML-based loggers that inserts anchor tags for paths.

_insert_anchors(level, escaped_text)[source]

Insert anchors for all paths in escaped_text.

Note

escaped_text should be valid html (e.g. the result of html.escape(text)).

class nutils.log.HtmlLog(file, *, title='nutils', scriptname=None, funcname=None, funcargs=None)[source]

Output html nested lists.

write(level, text)[source]

Write text with log level level to the log.

This method makes sure the current context is printed and calls _print_item().

write_post_mortem(etype, value, tb)[source]

write exception nfo to html log

class nutils.log.IndentLog(file, *, progressfile=None, progressinterval=None)[source]

Output indented html snippets.

class nutils.log.TeeLog(*logs)[source]

Simultaneously interface multiple logs

context(title)[source]

Return a context manager that adds a contextual layer named title.

Note

This function is abstract.

write(level, text)[source]

Write text with log level level to the log.

Note

This function is abstract.

nutils.log.range(title, *args)[source]

Progress logger identical to built in range

nutils.log.iter(title, iterable, length=None)[source]

Progress logger identical to built in iter

nutils.log.enumerate(title, iterable)[source]

Progress logger identical to built in enumerate

nutils.log.zip(title, *iterables)[source]

Progress logger identical to built in enumerate

nutils.log.count(title, start=0, step=1)[source]

Progress logger identical to itertools.count

nutils.log.title(f)[source]

Decorator, adds title argument with default value equal to the name of the decorated function, unless argument already exists. The title value is used in a static log context that is destructed with the function frame.