Skip to content

Commit

Permalink
Merge branch 'dev-2.0.0-beta-debugging' of https://github.com/Federat…
Browse files Browse the repository at this point in the history
…edAI/FATE into dev-2.0.0-beta-debugging
  • Loading branch information
nemirorox committed Jul 5, 2023
2 parents b3716aa + 31483b6 commit 4e3d524
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions python/fate/components/core/spec/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
import logging
import logging.config
import os
import pathlib
from typing import Literal

Expand Down Expand Up @@ -164,40 +165,55 @@ def add_file_handler(name, filename, level, formater="brief", filters=[]):
)
root_handlers.append(handler_name)

# add component_desc logger
component_handlers = []
component_base_path = self.metadata.basepath.joinpath("component_desc")
component_base_path.mkdir(parents=True, exist_ok=True)
filters["components"] = {"name": "fate.components"}
filters["ml"] = {"name": "fate.ml"}
for level in levels:
handler_name = f"component_{level.lower()}"
add_file_handler(
name=handler_name,
filename=component_base_path.joinpath(level),
level=level,
)
component_handlers.append(handler_name)
component_loggers = {
"fate.components": dict(
handlers=component_handlers,
filters=["components"],
level=self.metadata.level,
),
"fate.ml": dict(
handlers=component_handlers,
filters=["ml"],
level=self.metadata.level,
),
}
# add console logger when debug_mode is True
if os.environ.get("COMPONENT_DEBUG_MODE", "false").lower() == "true":
handler_name = f"root_console_{self.metadata.level.lower()}"
handlers[handler_name] = {
# "class": "logging.StreamHandler",
"class": "rich.logging.RichHandler",
# "formatter": "brief",
"level": self.metadata.level,
"filters": [],
# "stream": "ext://sys.stdout",
}
root_handlers.append(handler_name)

# add component_desc logger
# component_handlers = []
# component_base_path = self.metadata.basepath.joinpath("component_desc")
# component_base_path.mkdir(parents=True, exist_ok=True)
# filters["components"] = {"name": "fate.components"}
# filters["ml"] = {"name": "fate.ml"}
# for level in levels:
# handler_name = f"component_{level.lower()}"
# add_file_handler(
# name=handler_name,
# filename=component_base_path.joinpath(level),
# level=level,
# )
# component_handlers.append(handler_name)
loggers = {}
# component_loggers = {
# "fate.components": dict(
# handlers=component_handlers,
# filters=["components"],
# level=self.metadata.level,
# ),
# "fate.ml": dict(
# handlers=component_handlers,
# filters=["ml"],
# level=self.metadata.level,
# ),
# }
# loggers.update(component_loggers)
#
logging.config.dictConfig(
dict(
version=1,
formatters=formatters,
handlers=handlers,
filters=filters,
loggers=component_loggers,
loggers=loggers,
root=dict(handlers=root_handlers, level=self.metadata.level),
disable_existing_loggers=False,
)
Expand Down

0 comments on commit 4e3d524

Please sign in to comment.