_sub_tag() could not find tag
See original GitHub issueI have a simple program using a file as sink:
from loguru import logger
import os
logger.remove() # Remove the default logger
logfile = r'logfile.log'
loglevel = os.getenv('LOGLEVEL', 'INFO')
loglevel = loglevel.replace('"', '')
fmt='{time:YYYY:MM:DD HH:MM:SS} | {level: <8} | {name}:{function}:{line} - {message}'
logger.add(
logfile,
format=fmt,
level=loglevel
)
logger.trace ("TRACE priority message")
logger.debug ("DEBUG priority message")
logger.info ("INFO priority message")
logger.success ("SUCCESS priority message")
logger.warning ("WARNING priority message")
logger.error ("ERROR priority message")
logger.critical("CRITICAL priority message")
It shows the following errors:
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=14967), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'TRACE', 'line': 17, 'message': 'TRACE priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 778917, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=17965), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'DEBUG', 'line': 18, 'message': 'DEBUG priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 781915, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=28922), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'INFO', 'line': 19, 'message': 'INFO priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 792872, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=33908), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'SUCCESS', 'line': 20, 'message': 'SUCCESS priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 797858, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=40889), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'WARNING', 'line': 21, 'message': 'WARNING priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 804839, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=45878), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'ERROR', 'line': 22, 'message': 'ERROR priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 809828, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
--- Logging error in Loguru Handler #1 ---
Record was: {'elapsed': datetime.timedelta(microseconds=53855), 'exception': None, 'extra': {}, 'file': 'script.py', 'function': '<module>', 'level': 'CRITICAL', 'line': 23, 'message': 'CRITICAL priority message', 'module': 'script', 'name': '__main__', 'process': '6208', 'thread': '10716', 'time': datetime(2019, 11, 24, 1, 32, 19, 817805, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800), 'Malay Peninsula Standard Time'))}
Traceback (most recent call last):
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 89, in emit
precomputed_format = self._decolorize_format(dynamic_format)
File "C:\home\Anaconda3\lib\site-packages\loguru\_handler.py", line 209, in _decolorize_format
return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 174, in feed
text = self._regex_tag.sub(self._sub_tag, text)
File "C:\home\Anaconda3\lib\site-packages\loguru\_ansimarkup.py", line 248, in _sub_tag
"make sure you did not misspelled it" % markup
ValueError: Tag "<module>" does not corespond to any known ansi directive, make sure you did not misspelled it
--- End of logging error ---
However, if I remove the format=fmt
line, the code works perfectly.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
ElementTree from python doesn't find a child tag
I'm trying to access an element from a XML file from Python with ElementTree , and it doesn't find it. XML code: <item>...
Read more ><sup> and <sub> tag not working · Issue #339 - GitHub
So basically, it seems like the only option is to wrap the rendered <Text> component inside a <View> component for subscript/superscript cases, ...
Read more >Language tags in HTML and XML - W3C
For HTML and XML language markup, the case should not matter. Using the subtag registry. As mentioned above, you used to find subtags...
Read more >ffmpeg: "Could not find tag for codec none" - audio - Super User
I had a similar problem with a .mov file, and solved it using this info ...
Read more >How the Resource Management System matches language tags
The tags match on the language, script, and region subtags, ... Description: The comparison starts with "pt-PT" but does not find an exact ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think there was some confusion when you tried to debug this problem, this code snippet actually always worked fine. However, I think that at one time or another, you had something very slightly different that would generate the error, just a small typo:
Note the
format=format
. Thelogger
accepts a function to be passed to theformat
argument. In such case, Loguru will first call this function so that it dynamically generates the logs format instead of using a staticstr
(like yourfmt
variable). This dynamically generated format is then used to create the log message, just as the static one would have been.Here, the
format
function passed to theformat
argument is actually the built-informat()
. For this reason, Loguru will internally do something likefmt = format(record)
, which results in:Later, this will raise an error, because
fmt
is expected to look like"{time} - {message}"
so that Loguru can callmessage = fmt.format_map(record)
.That’s why I propose to add a check inside Loguru, to ensure that the
format
argument is different from theformat()
built-in. This is a mistake that can easily happen.Yes, as you taught me, the
set
command should be used without quotes. I prefer not to automaticallystrip()
the"
, I don’t think Loguru should try to fix incorrect usage of OS commands.Check for builtins
format()
andfilter()
incorrectly passed as arguments has been added to0.4.0
. The new error message is more explicit.