Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic logging configuration #3118

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 77 additions & 28 deletions docs/resources/log.config
Original file line number Diff line number Diff line change
@@ -1,28 +1,77 @@
[loggers]
keys=root

[handlers]
keys=consoleHandler,errorFileHandler

[formatters]
keys=baseFormatter

[logger_root]
level=INFO
handlers=consoleHandler,errorFileHandler

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

[handler_errorFileHandler]
class=FileHandler
level=ERROR
formatter=baseFormatter
args=('error_log.txt', 'a')

[formatter_baseFormatter]
class=nvflare.fuel.utils.log_utils.BaseFormatter
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"baseFormatter": {
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"colorFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"jsonFormatter": {
"()": "nvflare.fuel.utils.log_utils.JsonFormatter",
"fmt": "%(asctime)s - %(name)s - %(fullName)s - %(levelname)s - %(message)s"
}
},
"filters": {
"FLFilter": {
"()": "nvflare.fuel.utils.log_utils.LoggerNameFilter",
"logger_names": ["custom", "nvflare.app_common", "nvflare.app_opt"]
}
},
"handlers": {
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"filters": [],
"stream": "ext://sys.stdout"
},
"logFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "baseFormatter",
"filename": "log.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"errorFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"formatter": "baseFormatter",
"filename": "log_error.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"jsonFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "jsonFormatter",
"filename": "log.json",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10
},
"FLFileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "baseFormatter",
"filters": ["FLFilter"],
"filename": "log_fl.txt",
"mode": "a",
"maxBytes": 20971520,
"backupCount": 10,
"delay": true
}
},
"loggers": {
"root": {
"level": "INFO",
"handlers": ["consoleHandler", "logFileHandler", "errorFileHandler", "jsonFileHandler"]
}
}
}
5 changes: 4 additions & 1 deletion nvflare/apis/fl_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class AdminCommandNames(object):
SHELL_TAIL = "tail"
SHELL_GREP = "grep"
APP_COMMAND = "app_command"
CONFIGURE_JOB_LOG = "configure_job_log"
CONFIGURE_SITE_LOG = "configure_site_log"


class ServerCommandNames(object):
Expand All @@ -263,6 +265,7 @@ class ServerCommandNames(object):
HANDLE_DEAD_JOB = "handle_dead_job"
SERVER_STATE = "server_state"
APP_COMMAND = "app_command"
CONFIGURE_JOB_LOG = "configure_job_log"


class ServerCommandKey(object):
Expand Down Expand Up @@ -382,7 +385,7 @@ class WorkspaceConstants:
SITE_FOLDER_NAME = "local"
CUSTOM_FOLDER_NAME = "custom"

LOGGING_CONFIG = "log.config"
LOGGING_CONFIG = "log_config.json"
DEFAULT_LOGGING_CONFIG = LOGGING_CONFIG + ".default"
AUDIT_LOG = "audit.log"
LOG_FILE_NAME = "log.txt"
Expand Down
7 changes: 2 additions & 5 deletions nvflare/app_common/tie/py_applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import multiprocessing
import os
import sys
import threading
import time
from abc import ABC, abstractmethod

from nvflare.apis.workspace import Workspace
from nvflare.fuel.utils.log_utils import add_log_file_handler, configure_logging
from nvflare.fuel.utils.log_utils import configure_logging
from nvflare.security.logging import secure_format_exception, secure_log_traceback

from .applet import Applet
Expand Down Expand Up @@ -94,9 +93,7 @@ def start(self, app_ctx: dict):
if not self.in_process:
# enable logging
run_dir = self.workspace.get_run_dir(self.job_id)
log_file_name = os.path.join(run_dir, "applet_log.txt")
configure_logging(self.workspace)
add_log_file_handler(log_file_name)
configure_logging(self.workspace, dir_path=run_dir, file_prefix="applet")
self.runner.start(app_ctx)

# Note: run_func does not return until it runs to completion!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from nvflare.apis.workspace import Workspace
from nvflare.app_opt.xgboost.histogram_based_v2.defs import Constant
from nvflare.app_opt.xgboost.histogram_based_v2.runners.xgb_runner import AppRunner
from nvflare.fuel.utils.log_utils import add_log_file_handler, configure_logging, get_obj_logger
from nvflare.fuel.utils.log_utils import configure_logging, get_obj_logger
from nvflare.fuel.utils.validation_utils import check_object_type
from nvflare.security.logging import secure_format_exception, secure_log_traceback

Expand Down Expand Up @@ -65,8 +65,7 @@ def start(self, ctx: dict):
run_dir = self.workspace.get_run_dir(self.job_id)
log_file_name = os.path.join(run_dir, f"{self.app_name}_log.txt")
print(f"XGB Log: {log_file_name}")
configure_logging(self.workspace)
add_log_file_handler(log_file_name)
configure_logging(self.workspace, dir_path=run_dir, file_prefix=self.app_name)
self.runner.run(ctx)
self.stopped = True
except Exception as e:
Expand Down
Loading
Loading