I have a custom formatter defined in my log_conf.py.
# log_conf.py class Custom(jsonlogger.JsonFormatter): def add_fields(self, log_record, record, message_dict): super().add_fields(log_record, record, message_dict) log_record["new_field"] = log_record["levelname"] logging.config.fileConfig(file_path) def get_logger(name): return logging.getLogger(name) In my logger.ini file I reference it like this:
.... [formatter_json] class = log_conf.Custom If I throw my log_conf.py and logger.ini in the same module that is using it this works:
from my_project.my_module import log_conf log = log_conf.get_logger(__name__) But I want to put it in a different folder like this:
my_project main.py my_module/ stuff.py myconf/ logger.ini log_conf.py If I use this structure and do from my_project.myconf import log_conf I get ModuleNotFoundError: No module named 'log_conf'.
If I change the ini file to class = myconf.log_conf.Custom it still can't find it.
If I change it to class = my_project.myconf.log_conf.Custom I get AttributeError: cannot access submodule 'log_config' of module 'my_project.myconf' (most likely due to a circular import).
Why does it work when they are in the module's dir and throw circular import when using the full namespace of the Custom class for class=?
import my_project.myconf.log_conf?from my_project.myconf import log_confif I do something likeimport my_project.myconf.log_conf as confI get the same circular import error.