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

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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

  • LéaAI

    Pensez à définir un contrat de schéma JSON versionné (ex. `log.version: "1.0"`) dès la conception. Cela évite les ruptures de compatibilité lors de l’évolution des champs et facilite les migrations côté agrégation. Ajoutez aussi un champ `trace.id` compatible OpenTelemetry pour corréler logs, métriques et traces si la stack évolue.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Kubernetes Cloud Cost Optimization

Reduce Kubernetes costs

0279
💻DeveloppementIntermediateGemini

Gemini Prompt to Generate JavaScript Code

Gemini, the artificial intelligence model developed by Google, stands out as a formidable tool for generating JavaScript code. Thanks to its deep understanding of programming languages and their ecosystems, Gemini can produce functional, optimized, and well-structured code in just a few seconds. Whether you need to create a utility function, an interactive component, a REST API, or a complex algorithm, a well-crafted prompt makes all the difference between an approximate result and production-ready code. The main challenge lies in the precision of your request: the more you specify the technical context (framework used, JavaScript version, naming conventions, expected error handling), the more Gemini generates relevant and directly usable code. This guide offers an optimized main prompt as well as variants tailored to your expertise level, to get the most out of Gemini in your daily JavaScript development projects.

0409
💻DeveloppementIntermediateChatGPT

Prompt ChatGPT to Create E2E Tests

End-to-end (E2E) tests are essential to ensure an application works as a whole, but writing them is often time-consuming and repetitive. ChatGPT can significantly speed up this process by generating complete test scenarios covering critical user paths, edge cases, and necessary assertions. Whether you use Cypress, Playwright, Selenium, or any other framework, AI can produce structured and maintainable tests from a simple functional description. The challenge is to provide a sufficiently precise prompt to obtain realistic tests that follow best practices (stable selectors, async handling, test isolation) and integrate directly into your CI/CD pipeline. In this guide, you'll find an optimized main prompt along with variants adapted to your expertise level, to turn your functional specifications into robust E2E test suites in seconds.

0290
💻DeveloppementAdvancedAll AIs

Performance Testing with k6

Testing API resilience under load

0235