Skip to content

Instantly share code, notes, and snippets.

View 100gle's full-sized avatar
🌐
<p>You got it</p>

Xiaoyue Lin 100gle

🌐
<p>You got it</p>
View GitHub Profile
@100gle
100gle / README.md
Created January 26, 2024 08:21 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@100gle
100gle / README.md
Created December 14, 2023 02:57 — forked from liviaerxin/README.md
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload
@100gle
100gle / FlippableCard.tsx
Last active August 27, 2023 10:00
frontend
import { useState } from "react";
import { twMerge as tw } from "tailwind-merge";
export default function FlippableCard() {
const [hasFlipped, setHasFilpped] = useState(false);
return (
<div className="flex items-center justify-center min-h-screen">
<div
className={tw(