-
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.
Added xul.utils; removed legacy xul.log.
- Loading branch information
1 parent
d4f033a
commit 55774f7
Showing
9 changed files
with
50 additions
and
118 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
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
"""Xul utilities.""" | ||
|
||
import io | ||
import logging | ||
from typing import TextIO, Union | ||
|
||
|
||
def config_logger(log_level: int = logging.INFO) -> None: | ||
"""Configure the root logger and add console handler. | ||
log_level -- console log level [default 'info'] | ||
Console logging (sys.stderr) for the command line scripts. | ||
""" | ||
# Configure threshold log level for the root logger. | ||
logging.getLogger("").setLevel(logging.DEBUG) | ||
|
||
# Configure console handler (StreamHandler). | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(log_level) | ||
|
||
# Attach the console handler to the root logger. | ||
logging.getLogger("").addHandler(console_handler) | ||
|
||
|
||
def get_source_name(xml_source: Union[TextIO, str]) -> str: | ||
"""Return the name of XML source.""" | ||
if isinstance(xml_source, str): | ||
return xml_source | ||
if isinstance(xml_source, io.TextIOWrapper): | ||
# e.g. sys.stdin | ||
return xml_source.name | ||
if isinstance(xml_source, io.StringIO): | ||
return "StringIO" | ||
# ? | ||
return str(xml_source) |