Logging Best Practices, Part 2: General Best Practices

4 MIN READ
MIN READ

Isn't all logging pretty much the same? Logs appear by default, like magic, without any further intervention by teams other than simply starting a system… right?

While logging may seem like simple magic, there's a lot to consider. Logs don't just automatically appear for all levels of your architecture, and any logs that do automatically appear probably don't have all of the details that you need to successfully understand what a system is doing. We've talked about actionable logs in part 1 of our Logging Best Practices Series. Now let's take a look at some other general best practices for logging: using log levels and ensuring you have logs for all levels of your architecture.

Before we can get into different ways of constructing loglines, we need to talk about overall logging practices. All loglines have levels and types.

Log Levels

Log levels refer to how severe a message impacts a system, helping operations understand how to react. On a high level, there are typically seven or eight different levels to choose from, depending on which standard you're following. Let's take a look at the log4j standard [1]:

  • TRACE – An action happened—any action at all. This level significantly decreases performance because every tiny thing is dumped into the logs.
  • DEBUG – An action happened that transferred data inside of a component (a microservice, an API, a database, etc.). Debug messages are probably very familiar to most developers; we use them to understand when functions or methods were called and how data may have transformed across a single plane.
  • INFO – An action happened that transferred data from component to component. Generally, this level is the most used as a general message.
  • WARN – There's something wrong, but the problem isn't blocking the component from continuing to function. An example of this level would be a deprecation notice.
  • ERROR – Something went wrong with a specific component of your system causing a failure of part of the component's functions, but the rest of the component is still functioning. In this case, a function call may have failed, but the component is still processing data.
  • FATAL – The entire component has crashed and has no hope of recovering without manual intervention.

Different languages use different combinations of these seven levels or call them slightly different names. In Python, for example, you'll also see CRITICAL and won't see TRACE or FATAL [2]; syslog-based systems include emerg, alert, and critical to break FATAL out into finer detail and add notice while removing TRACE [3].

As a general best practice, use log levels consistently. Have a set plan for your entire team. You need to come to a team-wide agreement at the very least on which log levels to use for each situation as language standards aren't always strict. A company-wide agreement is even better for enabling the effective use of logging systems by your operations-focused teams as they often are handling multiple environments owned by various development-focused teams.

Log Only What You Need

On the flip side, don't just use INFO for everything! Log levels enable you to fine-tune your logs to show only the information you need when you need it. Are you on a production system and need to know only when a system is failing? Report only on ERROR or FATAL, and ensure that your code flags each error with the appropriate log level. On a dev box and want to watch the data flowing throughout your system? Report down to DEBUG or even TRACE, and update your code accordingly. If you don't use log levels, your systems will be less efficient as you'll likely be logging too much, and you probably won't have the information you need in a hurry to fix problems when they arise.

You shouldn't need to log everything that happens in your system all the time. Logging everything all the time leads to information overload that takes over your system and fills up your log files, and you don't end up with anything useful—or the useful bits are buried at the bottom of a haystack of noise. If you use logging levels to identify data needs, you can turn up or down the noise with a fine-tuned knob, avoiding overly noisy logging systems.

Log Generation

While you do get general logs from your platforms and operating systems, you won't get logs for your application unless you add them explicitly in your codebase, and you won't get logs for additional needs such as auditing without explicitly adding them. You need to generate logs for all of your different needs throughout the depth of your architecture. There are many types of logs: system logs, application logs, audit logs, etc. If one level of your architecture is not logging to the same log management system that you're using everywhere else, remedy that immediately.

Also, don't just print to stdout. Simply printing to standard output (or standard error) just means the messages you're sending get lost in the sands of time. Ensure you use a logger to send your data to a file, which you can then archive, parse, or otherwise use to match the needs that you have for that data.

On that same thread, don't assume auto-generated logs, especially ones created by an interpreter, are good enough. You're missing data or generating useless, non-actionable data if you're relying simply on auto-generated logs.

By the way, just like in grammar school, spelling counts! When you're trying to parse messages and search logs, a single misspelled word will get amplified tenfold, and you will miss context that you could very well have used in your troubleshooting efforts. Take the time to check your log messages in your codebase before committing them. After all, details do matter.

Finally, don't dump everything into your logs. It may be obvious, but you don't need to add "attachments" to your logs. Any kind of artifact generated that isn't a log message or a structured log object doesn't belong in your log stream. For example, if your function generates a spreadsheet based on a query on a database, don't include the entire spreadsheet in your log object. While that may seem innocuous in your local system, that artifact will fill up your available space extremely quickly on production, and you'll be dealing with noisy logs to boot. Your operations team will not thank you for it.

If you can stick to these recommendations for using log levels and generating logs, you should be well on your way to writing actionable logs, the number one priority of any logging plan.


Table of Contents

    Share Article

    RSS Feed

    Next blog post
    You're viewing our latest blog post.
    Previous blog post
    You're viewing our oldest blog post.
    Mezmo + Catchpoint deliver observability SREs can rely on
    Mezmo’s AI-powered Site Reliability Engineering (SRE) agent for Root Cause Analysis (RCA)
    What is Active Telemetry
    Launching an agentic SRE for root cause analysis
    Paving the way for a new era: Mezmo's Active Telemetry
    The Answer to SRE Agent Failures: Context Engineering
    Empowering an MCP server with a telemetry pipeline
    The Debugging Bottleneck: A Manual Log-Sifting Expedition
    The Smartest Member of Your Developer Ecosystem: Introducing the Mezmo MCP Server
    Your New AI Assistant for a Smarter Workflow
    The Observability Problem Isn't Data Volume Anymore—It's Context
    Beyond the Pipeline: Data Isn't Oil, It's Power.
    The Platform Engineer's Playbook: Mastering OpenTelemetry & Compliance with Mezmo and Dynatrace
    From Alert to Answer in Seconds: Accelerating Incident Response in Dynatrace
    Taming Your Dynatrace Bill: How to Cut Observability Costs, Not Visibility
    Architecting for Value: A Playbook for Sustainable Observability
    How to Cut Observability Costs with Synthetic Monitoring and Responsive Pipelines
    Unlock Deeper Insights: Introducing GitLab Event Integration with Mezmo
    Introducing the New Mezmo Product Homepage
    The Inconvenient Truth About AI Ethics in Observability
    Observability's Moneyball Moment: How AI Is Changing the Game (Not Ending It)
    Do you Grok It?
    Top Five Reasons Telemetry Pipelines Should Be on Every Engineer’s Radar
    Is It a Cup or a Pot? Helping You Pinpoint the Problem—and Sleep Through the Night
    Smarter Telemetry Pipelines: The Key to Cutting Datadog Costs and Observability Chaos
    Why Datadog Falls Short for Log Management and What to Do Instead
    Telemetry for Modern Apps: Reducing MTTR with Smarter Signals
    Transforming Observability: Simpler, Smarter, and More Affordable Data Control
    Datadog: The Good, The Bad, The Costly
    Mezmo Recognized with 25 G2 Awards for Spring 2025
    Reducing Telemetry Toil with Rapid Pipelining
    Cut Costs, Not Insights:   A Practical Guide to Telemetry Data Optimization
    Webinar Recap: Telemetry Pipeline 101
    Petabyte Scale, Gigabyte Costs: Mezmo’s Evolution from ElasticSearch to Quickwit
    2024 Recap - Highlights of Mezmo’s product enhancements
    My Favorite Observability and DevOps Articles of 2024
    AWS re:Invent ‘24: Generative AI Observability, Platform Engineering, and 99.9995% Availability
    From Gartner IOCS 2024 Conference: AI, Observability Data, and Telemetry Pipelines
    Our team’s learnings from Kubecon: Use Exemplars, Configuring OTel, and OTTL cookbook
    How Mezmo Uses a Telemetry Pipeline to Handle Metrics, Part II
    Webinar Recap: 2024 DORA Report: Accelerate State of DevOps
    Kubecon ‘24 recap: Patent Trolls, OTel Lessons at Scale, and Principle Platform Abstractions
    Announcing Mezmo Flow: Build a Telemetry Pipeline in 15 minutes
    Key Takeaways from the 2024 DORA Report
    Webinar Recap | Telemetry Data Management: Tales from the Trenches
    What are SLOs/SLIs/SLAs?
    Webinar Recap | Next Gen Log Management: Maximize Log Value with Telemetry Pipelines
    Creating In-Stream Alerts for Telemetry Data
    Creating Re-Usable Components for Telemetry Pipelines
    Optimizing Data for Service Management Objective Monitoring
    More Value From Your Logs: Next Generation Log Management from Mezmo
    A Day in the Life of a Mezmo SRE
    Webinar Recap: Applying a Data Engineering Approach to Telemetry Data
    Dogfooding at Mezmo: How we used telemetry pipeline to reduce data volume
    Unlocking Business Insights with Telemetry Pipelines
    Why Your Telemetry (Observability) Pipelines Need to be Responsive
    How Data Profiling Can Reduce Burnout
    Data Optimization Technique: Route Data to Specialized Processing Chains
    Data Privacy Takeaways from Gartner Security & Risk Summit
    Mastering Telemetry Pipelines: Driving Compliance and Data Optimization
    A Recap of Gartner Security and Risk Summit: GenAI, Augmented Cybersecurity, Burnout
    Why Telemetry Pipelines Should Be A Part Of Your Compliance Strategy
    Pipeline Module: Event to Metric
    Telemetry Data Compliance Module
    OpenTelemetry: The Key To Unified Telemetry Data
    Data optimization technique: convert events to metrics
    What’s New With Mezmo: In-stream Alerting
    How Mezmo Used Telemetry Pipeline to Handle Metrics
    Webinar Recap: Mastering Telemetry Pipelines - A DevOps Lifecycle Approach to Data Management
    Open-source Telemetry Pipelines: An Overview
    SRECon Recap: Product Reliability, Burn Out, and more
    Webinar Recap: How to Manage Telemetry Data with Confidence
    Webinar Recap: Myths and Realities in Telemetry Data Handling
    Using Vector to Build a Telemetry Pipeline Solution
    Managing Telemetry Data Overflow in Kubernetes with Resource Quotas and Limits
    How To Optimize Telemetry Pipelines For Better Observability and Security
    Gartner IOCS Conference Recap: Monitoring and Observing Environments with Telemetry Pipelines
    AWS re:Invent 2023 highlights: Observability at Stripe, Capital One, and McDonald’s
    Webinar Recap: Best Practices for Observability Pipelines
    Introducing Responsive Pipelines from Mezmo
    My First KubeCon - Tales of the K8’s community, DE&I, sustainability, and OTel
    Modernize Telemetry Pipeline Management with Mezmo Pipeline as Code
    How To Profile and Optimize Telemetry Data: A Deep Dive
    Kubernetes Telemetry Data Optimization in Five Steps with Mezmo
    Introducing Mezmo Edge: A Secure Approach To Telemetry Data
    Understand Kubernetes Telemetry Data Immediately With Mezmo’s Welcome Pipeline
    Unearthing Gold: Deriving Metrics from Logs with Mezmo Telemetry Pipeline
    Webinar Recap: The Single Pane of Glass Myth
    Empower Observability Engineers: Enhance Engineering With Mezmo
    Webinar Recap: How to Get More Out of Your Log Data
    Unraveling the Log Data Explosion: New Market Research Shows Trends and Challenges
    Webinar Recap: Unlocking the Full Value of Telemetry Data
    Data-Driven Decision Making: Leveraging Metrics and Logs-to-Metrics Processors
    How To Configure The Mezmo Telemetry Pipeline
    Supercharge Elasticsearch Observability With Telemetry Pipelines
    Enhancing Grafana Observability With Telemetry Pipelines
    Optimizing Your Splunk Experience with Telemetry Pipelines
    Webinar Recap: Unlocking Business Performance with Telemetry Data
    Enhancing Datadog Observability with Telemetry Pipelines
    Transforming Your Data With Telemetry Pipelines