-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a834a5
commit 9e373b6
Showing
12 changed files
with
133 additions
and
100 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
from .configuration_utilities import get_resource_config, apply_runtime_updates | ||
from .executor_utilities import get_executors | ||
from .logger_utilities import configure_logger | ||
from .logger_utilities import * | ||
from .memoization_utilities import id_for_memo_file | ||
|
||
__all__ = ["apply_runtime_updates", "get_resource_config", "get_executors", "configure_logger"] |
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 |
---|---|---|
@@ -1,27 +1,93 @@ | ||
DEFAULT_FORMAT = ( | ||
"%(created)f %(asctime)s %(processName)s-%(process)d " | ||
"%(threadName)s-%(thread)d %(name)s:%(lineno)d %(funcName)s %(levelname)s: " | ||
"%(message)s" | ||
) | ||
import traceback | ||
import logging | ||
from logging import config | ||
|
||
__all__ = ["LOGGING_CONFIG", "get_configured_logger", "ErrorLogger"] | ||
|
||
def configure_logger(name, file_path): | ||
|
||
LOGGING_CONFIG = { | ||
"version": 1.0, | ||
"formatters": { | ||
"standard": { | ||
"format": ( | ||
"[%(processName)s-%(process)d %(threadName)s-%(thread)d " | ||
"%(asctime)s %(levelname)s %(name)s] %(message)s" | ||
), | ||
}, | ||
}, | ||
"handlers": { | ||
"stdout": { | ||
"level": "INFO", | ||
"formatter": "standard", | ||
"class": "logging.StreamHandler", | ||
"stream": "ext://sys.stdout", | ||
}, | ||
"stderr": { | ||
"level": "INFO", | ||
"formatter": "standard", | ||
"class": "logging.StreamHandler", | ||
"stream": "ext://sys.stderr", | ||
}, | ||
"file": { | ||
"level": "INFO", | ||
"formatter": "standard", | ||
"class": "logging.FileHandler", | ||
"filename": "parsl.log", | ||
}, | ||
}, | ||
"loggers": { | ||
"task": {"level": "INFO", "handlers": ["file", "stdout"], "propagate": False}, | ||
"task.create_manifest": {}, | ||
"task.ic_to_wu": {}, | ||
"task.reproject_wu": {}, | ||
"task.kbmod_search": {}, | ||
"kbmod": {"level": "INFO", "handlers": ["file", "stdout"], "propagate": False}, | ||
}, | ||
} | ||
"""Default logging configuration for Parsl.""" | ||
|
||
|
||
def get_configured_logger(logger_name, file_path=None): | ||
"""Configure logging to output to the given file. | ||
Parameters | ||
---------- | ||
logger_name : `str` | ||
Name of the created logger instance. | ||
file_path : `str` or `None`, optional | ||
Path to the log file, if any | ||
""" | ||
Simple function that will create a logger object and configure it to write | ||
to a file at the specified path. | ||
Note: We import logging within the function because we expect this to be | ||
called within a parsl app.""" | ||
logconf = LOGGING_CONFIG.copy() | ||
if file_path is not None: | ||
logconf["handlers"]["file"]["filename"] = file_path | ||
config.dictConfig(logconf) | ||
logger = logging.getLogger() | ||
|
||
import logging | ||
return logging.getLogger(logger_name) | ||
|
||
|
||
class ErrorLogger: | ||
"""Logs received errors before re-raising them. | ||
Parameters | ||
---------- | ||
logger : `logging.Logger` | ||
Logger instance that will be used to log the error. | ||
silence_errors : `bool`, optional | ||
Errors are not silenced by default but re-raised. | ||
Set this to `True` to silence errors. | ||
""" | ||
|
||
if name in logging.Logger.manager.loggerDict: | ||
return logging.Logger.manager.loggerDict[name] | ||
def __init__(self, logger, silence_errors=False): | ||
self.logger = logger | ||
self.silence_errors = silence_errors | ||
|
||
logger = logging.getLogger(name) | ||
handler = logging.FileHandler(file_path) | ||
formatter = logging.Formatter(DEFAULT_FORMAT, datefmt="%Y-%m-%d %H:%M:%S") | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.DEBUG) | ||
def __enter__(self): | ||
return self | ||
|
||
return logger | ||
def __exit__(self, exc, value, tb): | ||
if exc is not None: | ||
msg = traceback.format_exception(exc, value, tb) | ||
msg = "".join(msg) | ||
self.logger.error(msg) | ||
return self.silence_errors |
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
Oops, something went wrong.