-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add logging final version #893
Merged
sarthakpati
merged 41 commits into
mlcommons:new-apis_v0.1.0-dev
from
benmalef:add_logging_final_version
Jul 24, 2024
Merged
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
fe75f9c
add logging implementation
benmalef 08550d6
update utils.__init__
benmalef ea42f95
change logging_config
benmalef f54641c
change logging_config
benmalef 10dee45
change logging_config
benmalef e0aa707
blacked gandlf_logger
benmalef d5493f1
add gandlf_setup in the entrypoints
benmalef 0d1ec65
blacked gandlf_logger
benmalef 8ee6308
blacked some files
benmalef 04fee16
blacked forward_pass
benmalef b5203cf
add logging testing
benmalef 06c9d80
update test_full
benmalef b29e4ef
Merge pull request #8 from benmalef/add_test_logging
benmalef abddbd7
black test_full
benmalef c25396c
add logging test in test_full
benmalef bd9ba0d
remove unnecessary imports
benmalef 57f02c9
black forward_pass
benmalef 78af3fa
Merge pull request #9 from benmalef/add_logging_test
benmalef f1a3dfc
change the logging test name
benmalef 7d6f25e
Add logging documentation (#10)
benmalef a2b834d
change the log format
benmalef fd434b2
Update docs/extending.md
benmalef 783cbad
Update docs/extending.md
benmalef 8736c11
Update docs/extending.md
benmalef cf740e8
Merge branch 'new-apis_v0.1.0-dev' into add_logging_final_version
sarthakpati 18921a9
Merge branch 'new-apis_v0.1.0-dev' into add_logging_final_version
sarthakpati ba795fe
Merge branch 'new-apis_v0.1.0-dev' into add_logging_final_version
sarthakpati 935d4a3
update gandlf_logger
benmalef af46472
remove unnecessary imports
benmalef 36da4d2
update gandlf_logger_setup
benmalef d357fff
Update GANDLF/utils/gandlf_logger.py
benmalef 3051b4b
Update GANDLF/utils/gandlf_logger.py
benmalef ca076df
change the default to create a tmp file
benmalef 50668b9
Merge branch 'new-apis_v0.1.0-dev' into add_logging_final_version
sarthakpati e129be1
fix the error
benmalef 05fa733
Update GANDLF/utils/gandlf_logger.py
benmalef e5bfd23
made proposed changes
benmalef f857e65
Update setup.py
benmalef ca64876
Merge branch 'new-apis_v0.1.0-dev' into add_logging_final_version
sarthakpati f425289
change the def name to logger_setup
benmalef 1364c22
made some code changes
benmalef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
version: 1 | ||
formatters: | ||
detailed: | ||
format: "%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(funcName)s:%(lineno)d - %(message)s" | ||
datefmt: "%Y-%m-%d %H:%M:%S" | ||
log_colors: | ||
DEBUG: "white" | ||
INFO: "green" | ||
WARNING: "yellow" | ||
ERROR: "red" | ||
CRITICAL: "bold_red" | ||
simple: | ||
(): colorlog.ColoredFormatter | ||
format: "%(log_color)s%(asctime)s - %(levelname)s - %(message)s" | ||
datefmt: "%Y-%m-%d %H:%M:%S" | ||
filters: | ||
warnings_filter: | ||
(): logging.Filter | ||
name: "py.warnings" | ||
info_only_filter: | ||
(): GANDLF.utils.gandlf_logging.InfoOnlyFilter | ||
handlers: | ||
stdoutHandler: # only display info level | ||
class: logging.StreamHandler | ||
level: INFO | ||
formatter: simple | ||
filters: [info_only_filter] | ||
stream: ext://sys.stdout | ||
stderrHandler: # display warning and above messages | ||
class: logging.StreamHandler | ||
level: WARNING | ||
formatter: detailed | ||
stream: ext://sys.stderr | ||
rotatingFileHandler: | ||
class: logging.handlers.RotatingFileHandler | ||
level: DEBUG | ||
formatter: detailed | ||
maxBytes: 10485760 | ||
benmalef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backupCount: 2 | ||
loggers: # you can add your customized logger | ||
debug_logger: | ||
level: DEBUG | ||
handlers: [stdoutHandler, rotatingFileHandler, stderrHandler] | ||
propagate: no | ||
root: | ||
level: DEBUG | ||
handlers: [stdoutHandler, rotatingFileHandler, stderrHandler] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,4 @@ | |
) | ||
|
||
from .data_splitter import split_data | ||
from .gandlf_logging import logger_setup, InfoOnlyFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,61 @@ | ||||||
import logging | ||||||
import yaml | ||||||
from pathlib import Path | ||||||
from importlib import resources | ||||||
import tempfile | ||||||
from GANDLF.utils import get_unique_timestamp | ||||||
|
||||||
|
||||||
def _create_tmp_log_file(): | ||||||
tmp_dir = Path(tempfile.gettempdir()) | ||||||
VukW marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
log_dir = Path.joinpath(tmp_dir, ".gandlf") | ||||||
log_dir.mkdir(parents=True, exist_ok=True) | ||||||
log_file = Path.joinpath(log_dir, get_unique_timestamp() + ".log") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
return log_file | ||||||
|
||||||
|
||||||
def _create_log_file(log_file): | ||||||
log_file = Path(log_file) | ||||||
log_file.write_text("Starting GaNDLF logging session \n") | ||||||
|
||||||
|
||||||
def _save_logs_in_file(log_file, config_path): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a nitpick - this function is not saving any logs, instead just configures logging. Maybe rename it to smth more relevant? For ex,
Suggested change
|
||||||
with resources.open_text("GANDLF", config_path) as file: | ||||||
config_dict = yaml.safe_load(file) | ||||||
config_dict["handlers"]["rotatingFileHandler"]["filename"] = str(log_file) | ||||||
logging.config.dictConfig(config_dict) | ||||||
|
||||||
|
||||||
def logger_setup(log_file=None, config_path="logging_config.yaml") -> None: | ||||||
""" | ||||||
It sets up the logger. Reads from logging_config. | ||||||
|
||||||
Args: | ||||||
log_file (str): dir path for saving the logs, defaults to `None`, at which time logs are flushed to console. | ||||||
config_path (str): file path for the configuration | ||||||
|
||||||
""" | ||||||
|
||||||
logging.captureWarnings(True) | ||||||
log_tmp_file = log_file | ||||||
if log_file is None: # create tmp file | ||||||
log_tmp_file = _create_tmp_log_file() | ||||||
logging.info(f"The logs are saved in {log_tmp_file}") | ||||||
_create_log_file(log_tmp_file) | ||||||
_save_logs_in_file(log_tmp_file, config_path) | ||||||
|
||||||
|
||||||
class InfoOnlyFilter(logging.Filter): | ||||||
""" | ||||||
Display only INFO messages. | ||||||
""" | ||||||
|
||||||
def filter(self, record): | ||||||
""" | ||||||
Determines if the specified record is to be logged. | ||||||
Args: | ||||||
record (logging.LogRecord): The log record to be evaluated. | ||||||
Returns: | ||||||
bool: True if the log record should be processed, False otherwise. | ||||||
""" | ||||||
return record.levelno == logging.INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ exclude *.toml | |
include setup.py | ||
include .dockerignore | ||
include Dockerfile-* | ||
include logging_config.yml |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove redundant old loglevel stuff here