Code Explainers

Code explainers tagged #logging

ruby
module SlowQueryLogger
  SLOW_QUERY_THRESHOLD_MS = 200.0
  IGNORED_PAYLOAD_NAMES = %w[SCHEMA TRANSACTION].freeze
 

Logging slow SQL queries in Rails

instrumentation logging pub-sub
Intermediate 7 steps
python
import logging
import uuid
from contextvars import ContextVar
 

Request ID tracing in FastAPI middleware

middleware context-variables request-tracing
Intermediate 7 steps
rust
use axum::{
    body::{Body, Bytes},
    extract::Request,
    http::StatusCode,

Logging request bodies in Axum middleware

middleware streaming-body logging
Intermediate 8 steps
typescript
import { AsyncLocalStorage } from 'node:async_hooks';
import { randomUUID } from 'node:crypto';
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

Request correlation IDs in NestJS with AsyncLocalStorage

async-local-storage middleware logging
Advanced 8 steps
python
import time
 
from flask import Flask, g, request
 

Timing requests with Flask hooks

middleware request-lifecycle instrumentation
Intermediate 5 steps
python
import logging
import re
 
 

Redacting secrets in Python log records

logging regex redaction
Intermediate 7 steps
rust
use std::time::Duration;
 
use axum::{
    body::Body,

Structured request tracing in Axum

middleware observability tracing
Intermediate 7 steps
ruby
class Credentials
  SENSITIVE = %i[password api_key secret_token access_key].freeze
  REDACTED = "[REDACTED]".freeze
 

Redacting secrets in Ruby object output

serialization introspection security
Intermediate 7 steps
python
import logging
import traceback
 
from flask import Blueprint, jsonify, request

Centralized JSON error handling in Flask

error-handling blueprints json-api
Intermediate 5 steps
javascript
const logger = require('./logger');
 
class AppError extends Error {
  constructor(message, statusCode = 500, details = null) {

Centralized error handling in Express

error-handling middleware custom-errors
Intermediate 8 steps
rust
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
    Json,

How a custom error type maps to HTTP in Axum

error-handling enums trait-implementation
Intermediate 7 steps
java
@Component
public class RequestTimingInterceptor implements HandlerInterceptor {
 
    private static final Logger log = LoggerFactory.getLogger(RequestTimingInterceptor.class);

How a Spring HandlerInterceptor times requests

interceptor request-lifecycle logging
Intermediate 6 steps
typescript
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,

How a NestJS logging interceptor works

interceptors rxjs logging
Intermediate 5 steps