diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-04-17 20:58:13 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-04-17 20:58:13 -0600 |
commit | dba12a02cc33b45fc9cc1395ee89f317ccf8da96 (patch) | |
tree | 5cfab03f37b3ba87820d1aa3ef20be422fde0a18 /src | |
parent | 6bec182703885761699f6d53bc9034933b03197e (diff) |
add debug flag, minor fix in readme
Diffstat (limited to 'src')
-rw-r--r-- | src/pyssg/__init__.py | 4 | ||||
-rw-r--r-- | src/pyssg/arg_parser.py | 3 | ||||
-rw-r--r-- | src/pyssg/pyssg.py | 14 |
3 files changed, 16 insertions, 5 deletions
diff --git a/src/pyssg/__init__.py b/src/pyssg/__init__.py index cdd4cd1..3bbfc27 100644 --- a/src/pyssg/__init__.py +++ b/src/pyssg/__init__.py @@ -4,9 +4,7 @@ from logging import Logger, StreamHandler from .per_level_formatter import PerLevelFormatter -# since this is the root package, setup the logger here, -# set DEBUG here for testing purposes, can't make it -# dynamic yet (with a flag, for example) +# since this is the root package, setup the logger here __LOG_LEVEL: int = logging.INFO log: Logger = logging.getLogger(__name__) log.setLevel(__LOG_LEVEL) diff --git a/src/pyssg/arg_parser.py b/src/pyssg/arg_parser.py index 90fb8c1..ec150fb 100644 --- a/src/pyssg/arg_parser.py +++ b/src/pyssg/arg_parser.py @@ -34,6 +34,9 @@ def get_parsed_arguments() -> Namespace: action='store_true', help='''force building all pages and not only the updated ones''') + parser.add_argument('--debug', + action='store_true', + help='''change logging level from info to debug''') # really not needed, too much bloat and case scenarios to check for, # instead, just read from config file or default config file """ diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py index 958b397..2844fbf 100644 --- a/src/pyssg/pyssg.py +++ b/src/pyssg/pyssg.py @@ -25,7 +25,17 @@ log: Logger = logging.getLogger(__name__) def main() -> None: args: dict[str, Union[str, bool]] = vars(get_parsed_arguments()) - if not len(sys.argv) > 1: + if args['debug']: + # need to modify the root logger specifically, + # as it is the one that holds the config + # (__name__ happens to resolve to pyssg in __init__) + root_logger: Logger = logging.getLogger('pyssg') + root_logger.setLevel(logging.DEBUG) + for handler in root_logger.handlers: + handler.setLevel(logging.DEBUG) + log.debug('changed logging level to DEBUG') + + if not len(sys.argv) > 1 or (len(sys.argv) == 2 and args['debug']): log.info('pyssg v%s - no arguments passed, --help for more', VERSION) sys.exit(0) @@ -77,7 +87,7 @@ def main() -> None: # TODO: add logging to all of the build part, that includes the builder, # database, discovery, page and parser if args['build']: - # start the db + log.debug('building the html files') db: Database = Database(os.path.join(config.get('path', 'src'), '.files')) db.read() |