Logging Best Practices, Part 6: Security and Compliance

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, log levels, logs for all components and needs, different methodologies for generating logs, and best practices specifically for text-based logging and structured logging. In this final article in the series, let's touch on security and compliance considerations for logging.

Ah, compliance. The bane of every engineer and the boon of any enterprise. If you've ever worked at a company that has a product that is compliant in some form with any system like PCI or HIPAA, you know the pain of working through the annual compliance audits. Logs in various forms are central to generating evidence, and there are some things to be aware of when generating logs in the first place to ensure that your audit experience is less painful [1]. There are a lot of additional things to consider and new practices coming out all the time, but this post should give you a good overview of where to start.

Logging, Security, and Compliance

First, let's set some context. Why should you care about logs in the context of security and compliance, especially if you're not at the point where you need to be compliant? Aside from being a central component to gathering evidence for an audit, logs are critical to identifying when and where unauthorized access occurred in any system. Let's imagine someone has gotten access to your systems. They immediately start rooting around, trying to find something of interest. However, they want to cover their tracks, and one of the first places they go to cover their tracks is to attempt to tamper with the logs [2]. There are ways to ensure that, even with attempts at log tampering, you can secure your logs enough to detect intrusion in this fashion. For that reason alone, logging is as critical to active security measures as it is to forensic ones like compliance.

From a compliance perspective, most if not all security standards require compliance with some sort of logging mechanism. For example, as of version 3.2.1 (the version from May 2018, which is current as of this writing) [3], the PCI DSS requirement 10 explicitly requires audit trails and other logging mechanisms to be present on all systems that can access or provide access to cardholder data. As a result, auditing processes involve gathering logs as compliance evidence and examining them for any potential violations. Good application event logs will speed up your audit process by virtue of being easy to read and clear about which applications were accessed by which users. If your logs are neatly kept, a security researcher or auditor will be able to get what they need quickly and efficiently.

Some Initial Best Practices to Consider

First, ensure you have an append-only log and/or ensure you have read-only archives of all of your logs. Append-only logs means each log line is appended to the end of a log file with no way to erase prior lines save deleting the file. Couple that with a read-only archive of your log files stored in a separately secured location (preferably more than one archive in more than one separate location!), and you can ensure that wiping audit logs takes a significant amount of time, buying your alerting mechanisms time to reach someone who can do something about it. Even if an attacker were to turn off logging, they can't turn it off retroactively other than deleting the log files themselves, and if an archive is stored in a separately secured location, they can't delete the archive without additional work [4].

Speaking of archives, you should take an extra step to mask or sanitize any personally identifiable information (PII) in your logs. While good development practices should dictate that PII only is stored when absolutely necessary and only in secured and hashed databases, a lot of people forget to ensure that the same PII never appears in logs other than a unique identifier (UID) that correlates with the same secured database. Logs are often overlooked when thinking through security, and considering they're often transported across networks, logs are one vector for gathering data that can be a bit more accessible than others.

Ensure that you have process alerts set up to know when a logging process has stopped working, been turned off, or been accessed from an unauthorized user. This kind of tamper detection alert ensures that your logs are always writing, especially to that read-only archive. One of the first things an intruder would try to do would be to turn off logging, and a process alert on a low level would help you notice this problem quickly.

There are no known users in a secure system, and that includes in the logs. Every single access should be logged, even from automated systems and others, as you never know what may have caused a problem or who may have gotten access to a secured system. Most compliance standards require this type of access tracking. As an example scenario, a momentary slip in a commit to source control or someone lurking in your chat system undetected while people are discussing a deployment system could provide an attacker with credentials for your CI/CD system, which then could have admin credentials to a separate system. That kind of scenario is why there are no known users. A happy side effect of following this best practice for security and compliance is that it will get easier to understand where and when a system or an application fails because you can trace back through identification of credentials that were used to the system or user that triggered a deployment or other event.

Separate out your concerns. Typically, most folks consider logging a violation of the classic software engineering separation of concerns principle and file the need under a cross-cutting concern. However, you still can and should abstract the logging need out and separate out the resulting logs from each concern. In Python, for example, abstract your logging library of choice to its own class, and set a separate logging location and any context using individual instances coupled with handlers [5]. In doing something like this, you ensure that someone needing access to logs about one concern doesn't get access to logs from another.

Finally, use the same best practices as before, especially these two: Use standard logging libraries, and use all logging levels wisely. I'm calling these two best practices out explicitly due to a couple reasons. First, a standard logging library that has a history of quality development probably has a lot more bandwidth than you do to think about security, like memory leaks or input data sanitization. A standard library can also ensure your format is standardized and recognized by multiple archive systems or other data storage and retrieval systems that make enacting compliance easier. Using logging levels, as we noted before, decreases the chances that someone turns off logging to reduce noise as they're provided with finer controls. You can then use those logging levels to tune alerting for security purposes or to share specific alerts with different teams.

Overall, logging is critical to security and compliance, and it's often a component that people miss when thinking through their security and compliance needs. The best practices I outlined here are by no means exhaustive, especially as the needs of any system can and will shift when you move from platform to platform. There are many considerations and constant new ways to implement better logging security. Instead, this list is intended to get you thinking about how logging should fit in an overall security and compliance strategy, and hopefully make your audit cycle a bit easier.


1: One great source is the Open Web Application Security Project® (OWASP®) cheatsheet on application event logging, which is worth reading in its entirety by everyone (yes, "web application" does include your system, even if it doesn't seem to!).

2. If you want to go down the rabbit hole and explore all of the ways attackers tamper with logs, there's many resources online, including academic papers and training courses. A quick search brought articles like this one (doi:10.1007/978-3-642-32946-3_12) and the various specs at CAPEC like CAPEC-93 on log injection, tampering, and forging.

3. You can access a copy of the PCI DSS standards yourself at the PCI/DSS library , and there are a lot of places online that summarize the details if you don't feel comfortable accepting the license agreement.

4. You still have to consider how to secure transmission of logs to a centralized server or of archives to a separate location; and there's discussions around tamper-proof hardware , using trusted timestamping (e.g., linked timestamping, hash-chaining) to provide a tamper-resistant archive, and other systems. All of that is out of the scope of this post.

5. For an example, see the Python logging cookbook on logging to multiple destinations.

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