Skip to content

Commit

Permalink
FIX: Logger (#392)
Browse files Browse the repository at this point in the history
* Fix duplication of logger when Pyaedt logger is initialized.

* Fix duplication of logger when Pyaedt logger is initialized.

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* Fix duplication of logger when Pyaedt logger is initialized.

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* Fix duplication of logger when Pyaedt logger is initialized.

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

---------

Co-authored-by: maxcapodi78 <Shark78>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
maxcapodi78 and pre-commit-ci[bot] authored Apr 19, 2024
1 parent 3e32c15 commit 7a5c4e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/pyedb/dotnet/edb_core/dotnet/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,11 @@ def __init__(self, edbversion, student_version=False):
"""Initialize DLLs."""
from pyedb.dotnet.clr_module import _clr, edb_initialized

if settings.enable_screen_logs:
self._logger.enable_stdout_log()
else: # pragma: no cover
self._logger.disable_stdout_log()
if not settings.use_pyaedt_log:
if settings.enable_screen_logs:
self._logger.enable_stdout_log()
else: # pragma: no cover
self._logger.disable_stdout_log()
if not edb_initialized: # pragma: no cover
self._logger.error("Failed to initialize Dlls.")
return
Expand Down
16 changes: 15 additions & 1 deletion src/pyedb/edb_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,18 @@ def glb(self):
return self._global


pyedb_logger = EdbLogger(to_stdout=settings.enable_screen_logs)
logger = logging.getLogger("Global")
if any("aedt_logger" in str(i) for i in logger.filters):
from pyaedt.generic.settings import settings as pyaedt_settings

from pyedb.generic.settings import settings as pyaedb_settings

pyedb_logger = pyaedt_settings.logger
pyaedb_settings.use_pyaedt_log = True
pyaedb_settings.logger = pyedb_logger

else:
pyedb_logger = EdbLogger(to_stdout=settings.enable_screen_logs)
from pyedb.generic.settings import settings as pyaedb_settings

pyaedb_settings.logger = pyedb_logger
28 changes: 20 additions & 8 deletions src/pyedb/generic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ def __init__(self):
self._global_log_file_size = 10
self._lsf_queue = None
self._edb_environment_variables = {}
self._use_pyaedt_log = False
self._logger = None

@property
def logger(self):
"""Active logger."""
return self._logger

@logger.setter
def logger(self, val):
self._logger = val

@property
def use_pyaedt_log(self):
"""Flag that disable Edb log when PyAEDT is used."""
return self._use_pyaedt_log

@use_pyaedt_log.setter
def use_pyaedt_log(self, value):
self._use_pyaedt_log = value

@property
def edb_environment_variables(self):
Expand Down Expand Up @@ -130,14 +150,6 @@ def enable_debug_methods_argument_logger(self):
def enable_debug_methods_argument_logger(self, val):
self._enable_debug_methods_argument_logger = val

@property
def logger(self):
"""Active logger."""
try:
return logging.getLogger("Global")
except: # pragma: no cover
return logging.getLogger(__name__)

@property
def enable_error_handler(self):
"""Flag for enabling and disabling the internal PyEDB error handling."""
Expand Down

0 comments on commit 7a5c4e9

Please sign in to comment.