log#

Logging for Tidy3d.

Functions

get_aware_datetime()

Get an aware current local datetime(with local timezone info)

get_logging_console()

Get console from logging handlers.

set_log_suppression(value)

Control log suppression for repeated messages.

set_logging_console([stderr])

Set stdout or stderr as console output

set_logging_file(fname[, filemode, level])

Set a file to write log to, independently from the stdout and stderr output chosen using set_logging_level().

set_logging_level([level])

Set tidy3d console logging level priority.

Classes

LogHandler

Handle log messages depending on log level

Logger

Custom logger to avoid the complexities of the logging module

class LogHandler[source]#

Handle log messages depending on log level

__init__(console, level)[source]#
handle(level, level_name, message)[source]#

Output log messages depending on log level

class Logger[source]#

Custom logger to avoid the complexities of the logging module

The logger can be used in a context manager to avoid the emission of multiple messages. In this case, the first message in the context is emitted normally, but any others are discarded. When the context is exited, the number of discarded messages of each level is displayed with the highest level of the captures messages.

Messages can also be captured for post-processing. That can be enabled through ‘set_capture’ to record all warnings emitted during model validation. A structured copy of all validation messages can then be recovered through ‘captured_warnings’.

__init__()[source]#
set_capture(capture)[source]#

Turn on/off tree-like capturing of log messages.

captured_warnings()[source]#

Get the formatted list of captured log messages.

__enter__()[source]#

If suppression is enabled, enter a consolidation context (only a single message is emitted).

__exit__(exc_type, exc_value, traceback)[source]#

Exist a consolidation context (report the number of messages discarded).

begin_capture()[source]#

Start capturing log stack for consolidated validation log.

This method is used before any model validation starts and is included in the initialization of ‘BaseModel’. It must be followed by a corresponding ‘end_capture’.

end_capture(model)[source]#

End capturing log stack for consolidated validation log.

This method is used after all model validations and is included in the initialization of ‘BaseModel’. It must follow a corresponding ‘begin_capture’.

log(level, message, *args, log_once=False)[source]#

Log (message) % (args) with given level

debug(message, *args, log_once=False)[source]#

Log (message) % (args) at debug level

info(message, *args, log_once=False)[source]#

Log (message) % (args) at info level

warning(message, *args, log_once=False, custom_loc=None, capture=True)[source]#

Log (message) % (args) at warning level

error(message, *args, log_once=False)[source]#

Log (message) % (args) at error level

critical(message, *args, log_once=False)[source]#

Log (message) % (args) at critical level

set_logging_level(level='WARNING')[source]#

Set tidy3d console logging level priority.

Parameters:

level (str) – The lowest priority level of logging messages to display. One of {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'} (listed in increasing priority).

set_log_suppression(value)[source]#

Control log suppression for repeated messages.

get_aware_datetime()[source]#

Get an aware current local datetime(with local timezone info)

set_logging_console(stderr=False)[source]#

Set stdout or stderr as console output

Parameters:

stderr (bool) – If False, logs are directed to stdout, otherwise to stderr.

set_logging_file(fname, filemode='w', level='WARNING')[source]#

Set a file to write log to, independently from the stdout and stderr output chosen using set_logging_level().

Parameters:
  • fname (str) – Path to file to direct the output to.

  • filemode (str) – ‘w’ or ‘a’, defining if the file should be overwritten or appended.

  • level (str) – One of {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}. This is set for the file independently of the console output level set by set_logging_level().

get_logging_console()[source]#

Get console from logging handlers.