Skip to content

Commit

Permalink
Add missed modifications for #226
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Franceschetti committed Apr 28, 2024
1 parent d8a154c commit ec9bbb9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1,072 deletions.
2 changes: 1 addition & 1 deletion mkdocs_macros/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def render(self, markdown: str, force_rendering:bool=False):
page=self.page,
)

trace('ERROR', error_message)
trace('ERROR', error_message, level='warning')
if on_error_fail:
exit(ERROR_MACRO)

Expand Down
39 changes: 23 additions & 16 deletions mkdocs_macros/util.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
from copy import deepcopy
import os, sys, importlib.util
from typing import Literal
from packaging.version import Version

from termcolor import colored
Expand Down Expand Up @@ -34,33 +35,39 @@ def format_trace(*args):
for the mkdocs-macros framework;
it will appear if --verbose option is activated
"""
# full_prefix = colored(TRACE_PREFIX, TRACE_COLOR)
# args = [full_prefix] + [str(arg) for arg in args]
# msg = ' '.join(args)
first = args[0]
rest = [str(el) for el in args[1:]]
text = "[%s] - %s" % (TRACE_PREFIX, first)
emphasized = colored(text, TRACE_COLOR)
return ' '.join([emphasized] + rest)

# def trace(*args, prefix=TRACE_PREFIX, **kwargs):
# """
# General purpose print function, with first item emphasized (color)
# This is NOT debug: it will always be printed
# """
# first = args[0]
# rest = args[1:]
# text = "[%s] %s" % (prefix, first)
# emphasized = colored(text, TRACE_COLOR)
# print(emphasized, *rest, **kwargs)
def trace(*args):

TRACE_LEVELS = {
'debug' : logging.DEBUG,
'info' : logging.INFO,
'warning' : logging.WARNING,
'error' : logging.ERROR,
'critical': logging.CRITICAL
}

def trace(*args, level:str='info'):
"""
General purpose print function, as trace,
for the mkdocs-macros framework;
it will appear unless --quiet option is activated
it will appear unless --quiet option is activated.
The level is 'debug', 'info', 'warning', 'error' or 'critical'.
"""
msg = format_trace(*args)
LOG.info(msg)
try:
LOG.log(TRACE_LEVELS[level], msg)
except KeyError:
raise ValueError("Unknown level '%s' %s" % (level,
tuple(TRACE_LEVELS.keys())
)
)
return msg
# LOG.info(msg)



Expand Down
Loading

0 comments on commit ec9bbb9

Please sign in to comment.