-
Notifications
You must be signed in to change notification settings - Fork 515
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
Add support of loguru logger. #653
Comments
#228 is very relevant for this, it's possible you will run into similar issues here. We are happy to accept and merge PRs for those things, generally speaking |
Hi! I just wanted to chime in with my solution here. Basically, all I did was this: from loguru import logger
from sentry_sdk.integrations.logging import (
LoggingIntegration,
BreadcrumbHandler,
EventHandler,
)
.
.
.
if settings.sentry_dsn:
_ = logger.add(
BreadcrumbHandler(level=logging.DEBUG),
diagnose=settings.loguru_diagnose,
level=logging.DEBUG,
)
_ = logger.add(
EventHandler(level=logging.ERROR),
diagnose=settings.loguru_diagnose,
level=logging.ERROR,
)
integrations = [
LoggingIntegration(level=None, event_level=None),
] I also work with a lib where I don't have much control over their use of the built-in logger, and so I have this snippet as well to intercept the built-in logger and route everything through loguru ( from the excellent loguru docs! ): class InterceptHandler(logging.Handler):
"""Intercepts builtin logging messages and routes them to Loguru"""
def emit(self, record):
# Get corresponding Loguru level if it exists
try:
level = logger.level(record.levelname).name
except ValueError:
level = record.levelno
# Find caller from where originated the logged message
frame, depth = logging.currentframe(), 2
while frame.f_code.co_filename == logging.__file__:
frame = frame.f_back
depth += 1
logger.opt(depth=depth, exception=record.exc_info).log(
level, record.getMessage()
)
# Enable interceptor
logging.basicConfig(handlers=[InterceptHandler()], level=0) |
Hello guys, we been using loguru for a while and I believe it would be a good option to integrate with Sentry |
@jtfidje where the |
settings is an instance of a Settings-class that inherits from from pydantic import BaseSettings
class Settings(BaseSettings):
"""My settings!"""
.
.
. I use this a lot to configure applications |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
@jtfidje I'm seeing some issues with what I believe how InterceptHandler is working - I posted a description here (Delgan/loguru#344 (comment)). In short, I'm seeing |
Hey guys! Sorry for not getting back to you. This is amazing work so far:
My question now is, how do we get this into a PR of the sentry-python repo? We do hat a checklist on how an Integration could/should look like: And also one could use the So anyone motivated? (I think if we pull this off, I can organize Sentry swag for everyone) |
@antonpirker Sounds fun! I'll try to help where I can :) Swag sounds very nice! O:-) |
Hey @jtfidje ! Could you look at all the information we have in this thread and see if the PRs and your code here can be merged into one thing that addresses all the problems? |
As the Loguru developer, I would like Loguru and Sentry to be seamlessly compatible! 👍 Basically the |
Hey @Delgan! Thanks for the info and the offer to help. So you already created an sort of Integration for Loguru with Sentry? Is this anything that you could put into a pull request? I have put this issue on the low prio internal backlog and also into a milestone. I don't yet know when we (Sentry) will have time to help because we are currently packed with other stuff. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Hey @antonpirker, sorry for the late answer. Time flies... Honestly I would not know which PR to open. I'm not a Sentry user myself, so I'm not in the best position to know how to improve integration with Loguru. I've seen that for now, it requires touching different Sentry configuration ( I'm still willing to help if anyone have interest in investigating this. 👍 |
Ok, thanks for the feedback. |
Hi, any update? We just deployed sentry in our project and thinking about using loguru as logger. |
* Add `loguru` integration Actually, this is the solution in comments under #653 adapted to codebase and tested as well. #653 (comment) I also changed `logging` integration to use methods instead of functions in handlers, as in that way we can easily overwrite parts that are different in `loguru` integration. It shouldn't be a problem, as those methods are private and used only in that file. --------- Co-authored-by: Anton Pirker <[email protected]>
Please add support for loguru. I can make pull request but I don't know how to correctly integrate structure loggers.
The text was updated successfully, but these errors were encountered: