Skip to content

Commit

Permalink
Add logging tutorial notebook (#3150)
Browse files Browse the repository at this point in the history
### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Quick tests passed locally by running `./runtest.sh`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated.
  • Loading branch information
SYangster authored Jan 22, 2025
1 parent 7bcbafb commit 9e118e4
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/resources/log_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
Expand All @@ -25,7 +25,7 @@
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": [],
"stream": "ext://sys.stdout"
},
Expand Down
8 changes: 4 additions & 4 deletions docs/user_guide/configurations/logging_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See the `configuration dictionary schema <(https://docs.python.org/3/library/log
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
Expand All @@ -52,7 +52,7 @@ See the `configuration dictionary schema <(https://docs.python.org/3/library/log
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": [],
"stream": "ext://sys.stdout"
},
Expand Down Expand Up @@ -147,7 +147,7 @@ Example configuration:

.. code-block:: json
"colorFormatter": {
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s",
"level_colors": {
Expand Down Expand Up @@ -221,7 +221,7 @@ Example configuration:
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "colorFormatter",
"formatter": "consoleFormatter",
"filters": ["FLFilter"],
"stream": "ext://sys.stdout"
}
Expand Down
84 changes: 84 additions & 0 deletions examples/tutorials/custom_log_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"baseFormatter": {
"()": "nvflare.fuel.utils.log_utils.BaseFormatter",
"fmt": "%(asctime)s - %(name)s - %(levelname)s - %(fl_ctx)s - %(message)s"
},
"consoleFormatter": {
"()": "nvflare.fuel.utils.log_utils.ColorFormatter",
"fmt": "%(asctime)s - %(identity)s - %(name)s - %(levelname)s - %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
"logger_colors": {
"NPModelPersistor": "blue"
}
},
"jsonFormatter": {
"()": "nvflare.fuel.utils.log_utils.JsonFormatter",
"fmt": "%(asctime)s - %(name)s - %(fullName)s - %(levelname)s - %(fl_ctx)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": "consoleFormatter",
"filters": ["FLFilter"],
"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", "FLFileHandler"]
},
"nvflare.app_common.aggregators": {
"level": "DEBUG"
}
}
}
Loading

0 comments on commit 9e118e4

Please sign in to comment.