log#
Logging for Tidy3d.
Functions
Get an aware current local datetime(with local timezone info) |
|
Get console from logging handlers. |
|
|
Control log suppression for repeated messages. |
|
Set stdout or stderr as console output |
|
Set a file to write log to, independently from the stdout and stderr output chosen using |
|
Set tidy3d console logging level priority. |
Classes
Handle log messages depending on log level |
|
Custom logger to avoid the complexities of the logging module |
- 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’.
- __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’.
- 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', 'SUPPORT', 'USER', INFO', 'WARNING', 'ERROR', 'CRITICAL'}
(listed in increasing priority).
- 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', log_path=False)[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. If empty string, a previously set logging file will be closed, if any, but nothing else happens.
filemode (str) – ‘w’ or ‘a’, defining if the file should be overwritten or appended.
level (str) – One of
{'DEBUG', 'SUPPORT', 'USER', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}
. This is set for the file independently of the console output level set byset_logging_level()
.log_path (bool = False) – Whether to log the path to the file that issued the message.