P
💻DeveloppementIntermediateAll AIs

Create a Structured Logging System for Your Applications

A complete prompt to generate a JSON structured logging system with level management, sensitive data masking, rotation and observability stack integration.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un ingénieur backend senior spécialisé en observabilité et monitoring. Conçois un système de logs structurés complet pour une application [LANGAGE/FRAMEWORK] en production.

Contexte du projet :

  • Type d'application : [TYPE_APPLICATION (ex: API REST, microservice, application web, CLI)]
  • Environnements cibles : [ENVIRONNEMENTS (ex: développement, staging, production)]
  • Volume estimé de logs : [VOLUME (ex: 1000 req/min, 10000 events/jour)]
  • Stack d'agrégation existante : [STACK_LOGS (ex: ELK, Grafana Loki, Datadog, aucune)]

Livre les éléments suivants :

  1. Architecture du système de logging :

    • Choix de la librairie de logging avec justification
    • Format structuré (JSON) avec schéma détaillé des champs obligatoires et optionnels
    • Niveaux de log (DEBUG, INFO, WARN, ERROR, FATAL) avec politique claire d'utilisation de chaque niveau et exemples concrets
  2. Implémentation du logger central :

    • Classe ou module de logging réutilisable avec configuration centralisée
    • Support du contexte de requête (request ID, user ID, session ID) via propagation automatique
    • Enrichissement automatique des logs (timestamp ISO 8601, hostname, PID, version de l'app)
    • Gestion des données sensibles : masquage automatique (mots de passe, tokens, emails) via patterns configurables
  3. Middlewares et intercepteurs :

    • Middleware de logging HTTP : méthode, URL, status code, durée, taille de la réponse
    • Intercepteur pour les appels base de données : requête (sans données sensibles), durée, nombre de résultats
    • Intercepteur pour les appels à des services externes : endpoint, durée, succès/échec
  4. Gestion des erreurs dans les logs :

    • Capture automatique des stack traces avec contexte enrichi
    • Corrélation des erreurs avec le request ID pour le traçage
    • Niveaux d'alerte selon la criticité avec seuils configurables
  5. Rotation et rétention :

    • Stratégie de rotation des fichiers (taille max, durée)
    • Politique de rétention par environnement
    • Configuration pour le streaming vers la stack d'agrégation
  6. Performance et bonnes pratiques :

    • Logging asynchrone pour ne pas bloquer le thread principal
    • Sampling des logs DEBUG/TRACE en production
    • Tests unitaires pour valider le format et le contenu des logs

Fournis le code complet, documenté, avec des commentaires expliquant chaque décision technique. Inclus un exemple d'utilisation dans un endpoint réel et un fichier de configuration par environnement.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt guides AI to produce a production-quality structured logging system. By specifying your <strong>language or framework</strong>, you get directly usable code. The <strong>[APPLICATION_TYPE]</strong> field adapts middlewares and interceptors to your real architecture.</p><p>JSON structured logs are essential for modern observability: they enable automated filtering, aggregation and alerting. The prompt covers often-neglected aspects like <strong>sensitive data masking</strong> (GDPR), <strong>request ID correlation</strong> for distributed debugging, and <strong>production sampling</strong> to control storage costs.</p><p>For better results, be specific about your existing stack in <strong>[LOG_STACK]</strong>. The AI will adapt output formats and transports accordingly. You can then iterate by requesting specific additions like Prometheus metrics or OpenTelemetry traces.</p>

Use Cases

Set up logging for a new REST API or microserviceReplace console.log or print calls with a professional structured logging systemPrepare an application for production deployment with complete observabilityDiagnose performance issues through enriched and correlated logs

Expected Output

A complete logging system with central logger source code, middlewares, per-environment configuration files, concrete usage examples and associated unit tests.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Stable Diffusion Prompt for Generating Python Code

Stable Diffusion, known for its powerful image generation, can also be used to create realistic visuals of Python code. Whether you need illustrations of code snippets for your presentations, blog posts, or educational materials, Stable Diffusion lets you generate stylized screenshots of code editors displaying Python. Unlike language models like ChatGPT or Claude that produce executable code, Stable Diffusion excels at creating photorealistic images depicting code on a screen, in an IDE, or in a terminal. This approach is especially useful for content creators, UX designers building development interface mockups, or trainers looking for impactful visuals without revealing their actual source code. By mastering the right prompts, you'll achieve convincing renderings of Python development screens with a professional aesthetic, consistent syntax colors, and careful framing. Here are the most effective prompts to make that happen.

0135
💻DeveloppementIntermediateAll AIs

DALL-E Prompt to Generate JavaScript Code

DALL-E, the image generation model developed by OpenAI, is not designed to produce executable JavaScript code. However, it can play a valuable complementary role in a JavaScript developer's workflow. DALL-E excels at creating visuals related to development: user interface mockups, architecture diagrams, data flow schemas, or illustrations to document your code. By crafting precise prompts, you can obtain visual representations of complex JavaScript concepts like closures, the event loop, or design patterns. These visuals then serve as references for implementing your code, creating attractive technical documentation, or designing educational materials. The approach is to use DALL-E as a rapid visual prototyping tool: generate a UI mockup, then translate it into JavaScript components. This method accelerates the design phase and reduces back-and-forth between designers and developers. In this guide, we offer optimized prompts to get the most out of DALL-E in your JavaScript development process, from UI prototyping to visual documentation of your code.

0196
💻DeveloppementAdvancedAll AIs

Terraform Multi-Environment Architecture

Managing multiple environments with Terraform

0139
💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

0152