-
Notifications
You must be signed in to change notification settings - Fork 697
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
Use Loguru with Azure App Insights and OpenTelemetry #1222
Comments
i'm using SINKs as destinations target and converting the record to based on this loguru/loguru/_simple_sinks.py Lines 43 to 60 in 3b66fb5
something like: import logging
import os
from loguru import logger
APP_ENV = os.getenv("APP_ENV", "dev")
logger.remove()
def sink_json(loguru_message):
# code to log as json
pass
def sink_azure_app_insights(loguru_message):
record = loguru_message.record
exc = record["exception"]
logging_logger = logging.getLogger("my-awesome-app")
logging_record = logging_logger.makeRecord(
f"{record['file'].name}:{record['line']}",
record["level"].no,
record["file"].path,
record["line"],
record["message"],
(),
(exc.type, exc.value, exc.traceback) if exc else None,
record["function"],
record["extra"],
)
if exc:
logging_record.exc_text = "\n"
logging_logger.handle(logging_record)
logger.configure(
handlers=[
{
"backtrace": False,
"diagnose": False,
"level": "DEBUG",
"serialize": True,
"sink": azure_app_insights if APP_ENV == "prod" else sink_json,
}
],
extra={},
) |
Would you be able to use the It should automatically propagate messagges to loggers of the standard |
@Delgan is my understanding that |
@oieduardorabelo Yes, this is correct. |
I wanted to know if there is some way to save the logs from Loguru in Azure App Insights? I know that logs are written automatically to App Insights when using the standard
logging
library, but I couldn't see any way to do withloguru
. When going to the Azure Portal and look into the Logs, I can not see any logs I used in my code, regardless of the log level.Thanks! :)
For context, my code to initialize
loguru
(used the code from another issue):The text was updated successfully, but these errors were encountered: