|
28 | 28 | from pathlib import Path |
29 | 29 | from importlib import metadata |
30 | 30 | from typing import Tuple, Union, List |
31 | | -import logging |
| 31 | +from logging import getLogger |
32 | 32 | from .due import due, Doi |
33 | 33 | try: |
34 | 34 | import tomllib |
|
61 | 61 | bidscoinroot = Path(__file__).parent |
62 | 62 | schemafolder = bidscoinroot/'schema' |
63 | 63 |
|
64 | | -# Get the BIDSCOIN_DEBUG environment variable to set the log-messages and logging level, etc |
65 | | -DEBUG = os.getenv('BIDSCOIN_DEBUG','').upper() in ('1', 'TRUE', 'Y', 'YES') |
| 64 | +# Get the LOGGER and BIDSCOIN_DEBUG environment variable to set the log-messages and logging level, etc |
| 65 | +LOGGER = getLogger(__name__) |
| 66 | +DEBUG = os.getenv('BIDSCOIN_DEBUG','').upper() in ('1', 'TRUE', 'Y', 'YES') |
66 | 67 |
|
67 | 68 | # Create a BIDScoin user configuration directory if needed |
68 | 69 | configdir = Path(os.getenv('BIDSCOIN_CONFIGDIR') or (Path.home() if os.access(Path.home(),os.W_OK) else Path(tempfile.gettempdir()))/'.bidscoin')/__version__ |
|
99 | 100 | path='bidscoin', version=__version__, cite_module=True, tags=['reference-implementation']) |
100 | 101 |
|
101 | 102 |
|
102 | | -class CustomLogger(logging.Logger): |
103 | | - """Extend the Logger class to add custom methods for the new levels""" |
104 | | - |
105 | | - # Define custom logging levels |
106 | | - BCDEBUG, BCDEBUG_LEVEL = 'BCDEBUG', 11 # NB: using the standard debug mode will generate may debug messages from imports |
107 | | - VERBOSE, VERBOSE_LEVEL = 'VERBOSE', 15 |
108 | | - SUCCESS, SUCCESS_LEVEL = 'SUCCESS', 25 |
109 | | - |
110 | | - # Add custom log levels to logging |
111 | | - logging.addLevelName(BCDEBUG_LEVEL, BCDEBUG) |
112 | | - logging.addLevelName(VERBOSE_LEVEL, VERBOSE) |
113 | | - logging.addLevelName(SUCCESS_LEVEL, SUCCESS) |
114 | | - |
115 | | - def bcdebug(self, message, *args, **kwargs): |
116 | | - """Custom BIDSCOIN DEBUG messages""" |
117 | | - if self.isEnabledFor(self.BCDEBUG_LEVEL): |
118 | | - self._log(self.BCDEBUG_LEVEL, message, args, **kwargs) |
119 | | - |
120 | | - def verbose(self, message, *args, **kwargs): |
121 | | - """Custom BIDSCOIN VERBOSE messages""" |
122 | | - if self.isEnabledFor(self.VERBOSE_LEVEL): |
123 | | - self._log(self.VERBOSE_LEVEL, message, args, **kwargs) |
124 | | - |
125 | | - def success(self, message, *args, **kwargs): |
126 | | - """Custom BIDSCOIN SUCCESS messages""" |
127 | | - if self.isEnabledFor(self.SUCCESS_LEVEL): |
128 | | - self._log(self.SUCCESS_LEVEL, message, args, **kwargs) |
129 | | - |
130 | | - |
131 | | -# Get a logger from the custom logger class |
132 | | -logging.setLoggerClass(CustomLogger) |
133 | | -LOGGER = logging.getLogger(__name__) |
134 | | - |
135 | | - |
136 | 103 | def check_version() -> Tuple[str, Union[bool, None], str]: |
137 | 104 | """ |
138 | 105 | Compares the BIDSCOIN version from the local metadata to the remote pypi repository |
|
0 commit comments