-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from spjuhel/develop
JOSS Version 1
- Loading branch information
Showing
19 changed files
with
214 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,22 +30,58 @@ | |
__version__ = importlib.metadata.version("boario") | ||
__author__ = "sjuhel <[email protected]>" | ||
|
||
# __minimum_python_version__ = "3.8" | ||
|
||
# Create a logger object. | ||
logger = logging.getLogger(__name__) | ||
logger.addHandler(logging.NullHandler()) | ||
|
||
DEBUGFORMATTER = logging.Formatter( | ||
fmt="%(asctime)s [%(levelname)s] - [%(filename)s > %(funcName)s() > %(lineno)s] - %(message)s", | ||
fmt="%(asctime)s - boario - [%(levelname)s] - [%(filename)s > %(funcName)s() > %(lineno)s] - %(message)s", | ||
datefmt="%H:%M:%S", | ||
) | ||
|
||
"""Debug file formatter.""" | ||
|
||
INFOFORMATTER = logging.Formatter( | ||
fmt="%(asctime)s [%(levelname)s] - %(message)s", | ||
fmt="%(asctime)s - boario - [%(levelname)s] - %(message)s", | ||
datefmt="%H:%M:%S", | ||
) | ||
"""Info file formatter.""" | ||
|
||
|
||
# Create a logger object. | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
# Console logger | ||
ch = logging.StreamHandler() | ||
ch.setLevel(logging.INFO) | ||
ch.setFormatter(INFOFORMATTER) | ||
|
||
# Avoid adding multiple handlers in case of repeated imports | ||
if not logger.handlers: | ||
logger.addHandler(ch) | ||
|
||
|
||
# Functions to activate/deactivate logging | ||
def deactivate_logging(): | ||
"""Deactivate logging for the package.""" | ||
logger.disabled = True | ||
|
||
|
||
def activate_logging(): | ||
"""Activate logging for the package.""" | ||
logger.disabled = False | ||
|
||
|
||
# Functions to disable/enable console logging | ||
def disable_console_logging(): | ||
"""Disable console logging for the package.""" | ||
logger.info( | ||
"Disabling logging. You can reenable it with `boario.enable_console_logging()`" | ||
) | ||
logger.removeHandler(ch) | ||
|
||
|
||
def enable_console_logging(): | ||
"""Enable console logging for the package.""" | ||
if ch not in logger.handlers: | ||
logger.addHandler(ch) | ||
|
||
|
||
try: | ||
import pygit2 | ||
|
@@ -55,12 +91,17 @@ | |
logger.info("You are using boario from branch %s", __git_branch__) | ||
except pygit2.GitError: | ||
logger.info( | ||
"Could not find git branch, this is normal if you installed boario from pip." | ||
"Could not find git branch, this is normal if you installed boario from pip/conda." | ||
) | ||
except ModuleNotFoundError: | ||
logger.info("Unable to tell git branch as pygit2 was not found.") | ||
|
||
|
||
logger.info( | ||
"Loaded boario module. You can disable logging in console with `boario.disable_console_logging()`." | ||
) | ||
|
||
|
||
@lru_cache(10) | ||
def warn_once(logger, msg: str): | ||
logger.warning(msg) | ||
|
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
Oops, something went wrong.