-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: how to use colors properly with custom levels/tags? #257
Comments
It sounds like you will need to create a custom handler to do that. Once a custom handler is written, you can easily control its |
Thank you for your time and answer. I still don't fully get how the parts play with each other. I tried this using a log = TaggingLogger(
'Test',
[
'info',
'warning',
'debug',
'event1',
'event2'
]
)
my_handler = MyLogHandler({})
log.handlers.append(my_handler)
log.event1('Test event1 tag')
log.event2('Test event2 tag') When I try write the handler, I am using the class MyLogHandler(ColorizingStreamHandlerMixin, TaggingHandler):
def get_color(self, record):
import ipdb; ipdb.set_trace() # BREAKPOINT
def emit(self, record):
import ipdb; ipdb.set_trace() # BREAKPOINT
if 'event1' in record.extra.get('tags', ()):
record.extra.update({'color': 'red'}) The emit is indeed being called. My initial thought was to add a Also, I am confused on how to use the log method itself with the
I am not sure how to achieve this with a Thank you once again. |
Your code above doesn't seem to be using Logbook loggers... the "handlers.append" approach is the way the native |
Hello,
I am trying to have custom colors for custom message types. For instance:
Tag: event1 -> red
Tag: event2 -> blue
Tag: event3 -> white
I first tried to have a custom
ColorizedStderrHandler
class as shown in this example. However I later noticed on the core features that:custom log levels are not supported, instead we strongly recommend using logging subclasses or log processors that inject tagged information into the log record for this purpose.
I am not sure how to do that, is there any example on how to get different colors with something that emulates
custom levels
i.e. tags?Thank you very much.
The text was updated successfully, but these errors were encountered: