logging

xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <springProperty scope="context" name="APP_NAME" source="spring.application.name"/>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>

Logging with SLF4J and Logback

java logging slf4j
by David Kumar 2 tabs
python
import threading


class MinuteRingBuffer:
    def __init__(self, window_minutes=15):
        if window_minutes < 1:

Rolling Per-Minute Log Aggregation with a Ring Buffer

logging metrics observability
by codesnips 3 tabs
python
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {message}',

Django logging configuration for production

django python logging
by Priya Sharma 1 tab
python
import uuid
import logging


class RequestIDMiddleware:
    def __init__(self, get_response):

Django middleware for request ID tracking

django python middleware
by Priya Sharma 1 tab
go
package observability

import (
  "context"
  "log/slog"
  "os"

Request-scoped slog logger with JSON output (Go 1.21+)

go logging observability
by Leah Thompson 1 tab
ruby
Rails.application.config.filter_parameters += [
  :password,
  :password_confirmation,
  :token,
  :authorization,
  :ssn,

Sanitizing logs so secrets and PII do not leak downstream

logging pii redaction
by Kai Nakamura 1 tab
java
package com.example.observability;

public final class CorrelationIdConstants {

    public static final String HEADER_NAME = "X-Correlation-Id";
    public static final String MDC_KEY = "correlationId";

Propagate a Correlation ID Through Every Log Line with an MDC Servlet Filter in Spring Boot

spring-boot logging mdc
by codesnips 4 tabs
java
package com.example.tracing;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;

Propagate a Correlation ID Through Servlet Requests With MDC and a Feign Interceptor

java servlet filter
by codesnips 3 tabs
go
package observability

import (
  "time"

  "go.uber.org/zap"

Sampling logs to reduce noise during high-QPS incidents

go logging observability
by Leah Thompson 1 tab
ruby
class ApplicationError < StandardError
  attr_reader :context

  class << self
    def context_keys(*keys)
      @context_keys = keys unless keys.empty?

Structured Exceptions with Context

rails observability exceptions
by codesnips 3 tabs
ruby
class ArticlesController < ApplicationController
  def index
    # Bounded queries: without preload, article.author in the view raises.
    @articles = Article
      .published
      .preload(:author, :tags)

Strict Loading to Catch N+1 in Development

rails activerecord performance
by codesnips 4 tabs
go
package logctx

import (
	"context"
	"log/slog"
)

Request-Scoped Structured Logging with slog and Context in Go

go logging slog
by codesnips 3 tabs