Skip to content

Commit df626d3

Browse files
committed
font-patcher: Unify logging calls [skip ci]
[why] Usually the variable `logger` holds the logger object and all logging calls got through that. But because we use the font filename as loggername that logger object can only be set up after the arguments have been parsed. If some messages are to be logged before the call needs to go to the root logger called as `logging` class. This means one needs to take `logger` or `logging` based on the time when someting is to be logged. That can be confusing and is easily wrong, especially if code is shifted. [how] Always use the `logger` variable and just let that point to the root logger until we set up a concrete logger. Signed-off-by: Fini Jastrow <[email protected]>
1 parent d385603 commit df626d3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

font-patcher

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import absolute_import, print_function, unicode_literals
77

88
# Change the script version when you edit this script:
9-
script_version = "4.4.0"
9+
script_version = "4.4.1"
1010

1111
version = "3.0.2"
1212
projectName = "Nerd Fonts"
@@ -1878,7 +1878,7 @@ def setup_arguments():
18781878
args = parser.parse_args()
18791879

18801880
if args.makegroups > 0 and not FontnameParserOK:
1881-
logging.critical("FontnameParser module missing (bin/scripts/name_parser/Fontname*), specify --makegroups 0")
1881+
logger.critical("FontnameParser module missing (bin/scripts/name_parser/Fontname*), specify --makegroups 0")
18821882
sys.exit(1)
18831883

18841884
# if you add a new font, set it to True here inside the if condition
@@ -1913,22 +1913,22 @@ def setup_arguments():
19131913
args.complete = font_complete
19141914

19151915
if args.nonmono and args.single:
1916-
logging.warning("Specified contradicting --variable-width-glyphs and --use-single-width-glyph. Ignoring --variable-width-glyphs.")
1916+
logger.warning("Specified contradicting --variable-width-glyphs and --use-single-width-glyph. Ignoring --variable-width-glyphs.")
19171917
args.nonmono = False
19181918

19191919
make_sure_path_exists(args.outputdir)
19201920
if not os.path.isfile(args.font):
1921-
logging.critical("Font file does not exist: %s", args.font)
1921+
logger.critical("Font file does not exist: %s", args.font)
19221922
sys.exit(1)
19231923
if not os.access(args.font, os.R_OK):
1924-
logging.critical("Can not open font file for reading: %s", args.font)
1924+
logger.critical("Can not open font file for reading: %s", args.font)
19251925
sys.exit(1)
19261926
is_ttc = len(fontforge.fontsInFile(args.font)) > 1
19271927
try:
19281928
source_font_test = TableHEADWriter(args.font)
19291929
args.is_variable = source_font_test.find_table([b'avar', b'cvar', b'fvar', b'gvarb', b'HVAR', b'MVAR', b'VVAR'], 0)
19301930
if args.is_variable:
1931-
logging.warning("Source font is a variable open type font (VF), opening might fail...")
1931+
logger.warning("Source font is a variable open type font (VF), opening might fail...")
19321932
except:
19331933
args.is_variable = False
19341934
finally:
@@ -1943,25 +1943,27 @@ def setup_arguments():
19431943
args.extension = '.' + args.extension
19441944
if re.match("\.ttc$", args.extension, re.IGNORECASE):
19451945
if not is_ttc:
1946-
logging.critical("Can not create True Type Collections from single font files")
1946+
logger.critical("Can not create True Type Collections from single font files")
19471947
sys.exit(1)
19481948
else:
19491949
if is_ttc:
1950-
logging.critical("Can not create single font files from True Type Collections")
1950+
logger.critical("Can not create single font files from True Type Collections")
19511951
sys.exit(1)
19521952

19531953
if isinstance(args.xavgwidth, int) and not isinstance(args.xavgwidth, bool):
19541954
if args.xavgwidth < 0:
1955-
logging.critical("--xavgcharwidth takes no negative numbers")
1955+
logger.critical("--xavgcharwidth takes no negative numbers")
19561956
sys.exit(2)
19571957
if args.xavgwidth > 16384:
1958-
logging.critical("--xavgcharwidth takes only numbers up to 16384")
1958+
logger.critical("--xavgcharwidth takes only numbers up to 16384")
19591959
sys.exit(2)
19601960

19611961
return args
19621962

1963-
19641963
def main():
1964+
global logger
1965+
logging.basicConfig(format='%(levelname)s: %(message)s')
1966+
logger = logging # Use root logger until we can set up something sane
19651967
global version
19661968
git_version = check_version_with_git(version)
19671969
allversions = "Patcher v{} ({}) (ff {})".format(
@@ -1972,7 +1974,6 @@ def main():
19721974
check_fontforge_min_version()
19731975
args = setup_arguments()
19741976

1975-
global logger
19761977
logger = logging.getLogger(os.path.basename(args.font))
19771978
logger.setLevel(logging.DEBUG)
19781979
log_to_file = (args.debugmode & 1 == 1)

0 commit comments

Comments
 (0)