Skip to content

Commit

Permalink
Merge branch 'main' into job_launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanTingHsieh authored Oct 31, 2024
2 parents a84d7a3 + d91b111 commit 1d94eb4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
18 changes: 9 additions & 9 deletions docs/resources/log.config
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
[loggers]
keys=root,modelLogger
keys=root

[handlers]
keys=consoleHandler
keys=consoleHandler,errorFileHandler

[formatters]
keys=fullFormatter

[logger_root]
level=INFO
handlers=consoleHandler

[logger_modelLogger]
level=DEBUG
handlers=consoleHandler
qualname=modelLogger
propagate=0
handlers=consoleHandler,errorFileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=fullFormatter
args=(sys.stdout,)

[handler_errorFileHandler]
class=FileHandler
level=ERROR
formatter=fullFormatter
args=('error.log', 'a')

[formatter_fullFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
10 changes: 8 additions & 2 deletions nvflare/lighter/impl/master_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,27 @@ log_config: |
keys=root
[handlers]
keys=consoleHandler
keys=consoleHandler,errorFileHandler
[formatters]
keys=fullFormatter
[logger_root]
level=INFO
handlers=consoleHandler
handlers=consoleHandler,errorFileHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=fullFormatter
args=(sys.stdout,)
[handler_errorFileHandler]
class=FileHandler
level=ERROR
formatter=fullFormatter
args=('error.log', 'a')
[formatter_fullFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
Expand Down
10 changes: 8 additions & 2 deletions nvflare/private/fed/app/simulator/log.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
keys=root

[handlers]
keys=consoleHandler
keys=consoleHandler,errorFileHandler

[formatters]
keys=fullFormatter

[logger_root]
level=INFO
handlers=consoleHandler
handlers=consoleHandler,errorFileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=fullFormatter
args=(sys.stdout,)

[handler_errorFileHandler]
class=FileHandler
level=ERROR
formatter=fullFormatter
args=('error.log', 'a')

[formatter_fullFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
33 changes: 32 additions & 1 deletion nvflare/private/fed/utils/fed_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,45 @@
from .app_authz import AppAuthzService


def add_logfile_handler(log_file):
def add_logfile_handler(log_file: str):
"""Adds a log file handler to the root logger.
The purpose for this is to handle dynamic log file locations.
If a handler named errorFileHandler is found, it will be used as a template to
create a new handler for writing to the error.log file at the same directory as log_file.
The original errorFileHandler will be removed and replaced by the new handler.
Each log file will be rotated when it reaches 20MB.
Args:
log_file (str): log file path
"""
root_logger = logging.getLogger()
configured_handlers = root_logger.handlers
main_handler = root_logger.handlers[0]
file_handler = RotatingFileHandler(log_file, maxBytes=20 * 1024 * 1024, backupCount=10)
file_handler.setLevel(main_handler.level)
file_handler.setFormatter(main_handler.formatter)
root_logger.addHandler(file_handler)

configured_error_handler = None
for handler in configured_handlers:
if handler.get_name() == "errorFileHandler":
configured_error_handler = handler
break

if not configured_error_handler:
return

error_log_file = os.path.join(os.path.dirname(log_file), "error.log")
error_file_handler = RotatingFileHandler(error_log_file, maxBytes=20 * 1024 * 1024, backupCount=10)
error_file_handler.setLevel(configured_error_handler.level)
error_file_handler.setFormatter(configured_error_handler.formatter)

root_logger.addHandler(error_file_handler)
root_logger.removeHandler(configured_error_handler)


def _check_secure_content(site_type: str) -> List[str]:
"""To check the security contents.
Expand Down

0 comments on commit 1d94eb4

Please sign in to comment.