Loading content...
In the world of distributed systems security, there is one axiom that stands above all others: you cannot protect what you cannot see. Security event logging is the discipline that provides this visibility—the systematic collection, storage, and organization of security-relevant events that enables detection, investigation, and response to threats.
When a security breach occurs, the first question asked is invariably: "What happened?" The quality of your security logging determines whether you can answer this question in minutes, hours, or never. Organizations with mature security logging practices can reconstruct attack timelines, identify compromised assets, determine data exposure, and establish the blast radius of incidents. Those without comprehensive logging are left fumbling in the dark, making educated guesses while attackers maintain persistence.
Beyond incident response, security event logging forms the foundation for proactive threat detection, compliance attestation, forensic investigation, and security analytics. It is the raw material from which security insights are derived. Without robust logging, advanced security capabilities like SIEM systems, user behavior analytics, and threat hunting become impossible.
By the end of this page, you will understand what constitutes security event logging, which events must be captured for comprehensive security visibility, how to design log formats that enable analysis, and how to architect centralized logging systems that scale while maintaining integrity. You'll gain the knowledge to implement logging that transforms your security posture from reactive guessing to informed decision-making.
Security event logging is fundamentally different from operational logging, although they share infrastructure. While operational logs focus on system health, performance, and debugging, security logs are specifically designed to capture events that have security relevance—actions that could indicate attacks, policy violations, or compliance-relevant activities.
The Core Purpose of Security Logging
Security event logging serves multiple critical functions:
There's an inherent tension in security logging: you need enough detail to detect and investigate incidents, but excessive logging creates noise that obscures threats, increases storage costs, and can itself become a security liability if logs contain sensitive data. Mastering security logging requires understanding this balance and making deliberate choices about what to capture.
Security vs. Operational Logging
Consider the difference in perspective between these two disciplines:
An operational log for a failed login might read:
[ERROR] Authentication failed for user jdoe - invalid password
A security log for the same event captures far more context:
{
"timestamp": "2024-01-15T14:32:17.892Z",
"event_type": "authentication.failure",
"event_category": "authentication",
"outcome": "failure",
"reason": "invalid_password",
"user": {
"name": "jdoe",
"domain": "corporate",
"id": "usr_abc123"
},
"source": {
"ip": "192.168.1.105",
"geo": {"country": "US", "city": "Seattle"},
"user_agent": "Mozilla/5.0..."
},
"target": {
"application": "employee-portal",
"resource": "/api/auth/login"
},
"authentication": {
"method": "password",
"mfa_required": true,
"mfa_completed": false
},
"session": {
"previous_failures": 2,
"time_since_last_failure": "PT30S"
}
}
The security log enables answering questions like:
Determining what events to log is one of the most critical decisions in security architecture. Log too little, and you miss attacks. Log too much, and you drown in noise while incurring massive storage costs. The key is to identify events with security significance—those that indicate or could indicate security-relevant activity.
A comprehensive security event taxonomy covers several major categories:
| Category | Event Types | Security Relevance |
|---|---|---|
| Authentication Events | Login success/failure, logout, session creation, session termination, MFA challenges, password resets | Detect credential attacks, account takeover, unauthorized access attempts |
| Authorization Events | Access granted/denied, privilege escalation, role changes, permission modifications | Detect lateral movement, privilege abuse, policy violations |
| Administrative Actions | User creation/deletion, configuration changes, policy modifications, system updates | Detect insider threats, malicious admins, configuration tampering |
| Data Access Events | File reads/writes, database queries, API calls, exports, downloads | Detect data exfiltration, unauthorized access to sensitive data |
| Network Events | Connection attempts, firewall blocks, DNS queries, traffic anomalies | Detect network attacks, C2 communications, lateral movement |
| System Events | Process execution, service starts/stops, kernel events, driver loads | Detect malware execution, rootkits, persistence mechanisms |
| Security Tool Events | Antivirus detections, IDS alerts, WAF blocks, vulnerability scan results | Direct security indicators requiring investigation |
Authentication Events - The First Line of Detection
Authentication events are often the most valuable security logs because they represent the boundary between anonymous and identified users. Every access to your system begins with authentication, making these events critical for detecting:
Authentication logs should capture:
Authorization and Access Control Events
While authentication determines who someone is, authorization determines what they can do. Authorization events are crucial for detecting:
Authorization logs should capture:
Administrative Actions - Configuration Integrity
Administrative actions represent some of the highest-risk events because they can affect system security posture. An attacker with administrative access can:
Administrative action logging must be tamper-resistant. If an admin can both perform actions and delete the logs of those actions, the logging provides false assurance. Best practices include:
Apply the most comprehensive logging to your most valuable assets. Identify your 'crown jewels' (customer PII databases, financial systems, intellectual property repositories) and ensure every access to these systems is logged with maximum context. Lesser systems can use proportionally less detailed logging, balancing security with cost.
The format of your security logs profoundly affects their utility. Well-designed log formats enable automated parsing, efficient storage, powerful querying, and meaningful correlation. Poorly designed formats create parsing nightmares, lose critical context, and make analysis labor-intensive.
Structured vs. Unstructured Logs
The security industry has largely moved from unstructured text logs to structured formats, and for good reason:
Jan 15 14:32:17 auth failed user jdoe from 192.168.1.105{"timestamp":"...","event":"auth.failure",...}Adopting Industry Standards
Rather than inventing your own log format, adopt established standards that provide:
Major Security Log Standards:
Elastic Common Schema (ECS) — A framework for structuring data with common fields for categories like host, user, source, destination, and event. Widely adopted in the Elastic ecosystem but usable anywhere.
Open Cybersecurity Schema Framework (OCSF) — An open-source project backed by AWS, Splunk, IBM, and others that defines a vendor-agnostic schema for security events. Designed specifically for security use cases.
CEF (Common Event Format) — An older format developed by ArcSight, still widely used in legacy SIEM deployments. Structured but uses a custom syntax rather than JSON.
Syslog (RFC 5424) — The traditional Unix logging standard, still relevant for network devices and operating systems. Modern implementations support structured data extensions.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Security Event", "type": "object", "required": ["@timestamp", "event", "source"], "properties": { "@timestamp": { "type": "string", "format": "date-time", "description": "Event timestamp in ISO 8601 format with milliseconds" }, "event": { "type": "object", "required": ["category", "type", "outcome"], "properties": { "category": { "type": "string", "enum": ["authentication", "authorization", "network", "file", "process", "admin", "iam"], "description": "High-level event category" }, "type": { "type": "string", "description": "Specific event type within category" }, "action": { "type": "string", "description": "Action performed (login, access, create, etc.)" }, "outcome": { "type": "string", "enum": ["success", "failure", "unknown"], "description": "Result of the action" }, "reason": { "type": "string", "description": "Why outcome occurred (for failures)" }, "severity": { "type": "integer", "minimum": 0, "maximum": 10, "description": "Security severity 0 (info) to 10 (critical)" } } }, "source": { "type": "object", "properties": { "ip": { "type": "string", "format": "ipv4" }, "port": { "type": "integer" }, "geo": { "type": "object", "properties": { "country_iso_code": { "type": "string" }, "city_name": { "type": "string" }, "location": { "type": "object", "properties": { "lat": { "type": "number" }, "lon": { "type": "number" } } } } }, "user_agent": { "type": "string" } } }, "user": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "email": { "type": "string", "format": "email" }, "roles": { "type": "array", "items": { "type": "string" } } } }, "target": { "type": "object", "properties": { "service": { "type": "string" }, "resource": { "type": "string" }, "action": { "type": "string" } } }, "trace": { "type": "object", "properties": { "id": { "type": "string" }, "span_id": { "type": "string" }, "parent_span_id": { "type": "string" } } } }}Essential Fields for Security Events
Regardless of which standard you adopt, ensure your security events include these critical fields:
Temporal Fields:
@timestamp: When the event occurred (source system time, UTC preferred)event.ingested: When the log was received by central systemevent.created: When the event record was created (if different from occurrence)Actor Fields:
user.id: Immutable user identifieruser.name: Human-readable usernameuser.email: Email if availableuser.roles: Active roles at time of eventuser.effective_id: If acting as another user (sudo, impersonation)Source Fields:
source.ip: Client IP addresssource.geo: Geolocation data derived from IPsource.user_agent: Client identifier stringsource.device: Device fingerprint or identifier if availableEvent Classification:
event.category: Broad category (authentication, authorization, etc.)event.type: Specific type within categoryevent.action: The action performedevent.outcome: Success, failure, unknownevent.severity: Numeric severity for prioritizationCorrelation Fields:
trace.id: Distributed tracing ID for request correlationsession.id: User session identifiertransaction.id: Business transaction identifierIn distributed systems, security events are generated across dozens or hundreds of services, each producing logs locally. A centralized logging architecture aggregates these events into a unified platform where they can be searched, analyzed, correlated, and retained according to policy.
Centralized logging is not optional for security—it's mandatory. Without centralization:
Collection Layer: Getting Logs Off the Source
The collection layer is responsible for reliably moving logs from source systems to the central platform. Key considerations:
Log Agents (Filebeat, Fluent Bit, Vector): Software running on each host that reads logs from files or stdout and ships them to the transport layer. Agents should:
Syslog Receivers: Many network devices, load balancers, and security appliances only support syslog. Deploy dedicated syslog collectors (rsyslog, syslog-ng) that forward to your transport layer.
API Collectors: Cloud services and SaaS applications expose logs via APIs. Deploy collectors that poll these APIs and normalize events to your schema.
Security Considerations for Collection:
Transport Layer: Reliable, Scalable Delivery
The transport layer moves logs from collectors to processing. Modern architectures use message queues (Kafka, Kinesis, Pulsar) rather than direct connections. Benefits:
Kafka Cluster Design for Security Logs:
Topic: security-events-raw
Partitions: 24 (scale with ingestion rate)
Replication Factor: 3 (durability)
Retention: 7 days (pre-processing buffer)
Compaction: disabled (need all events)
Topic: security-events-normalized
Partitions: 24
Replication Factor: 3
Retention: 7 days
Topic: security-alerts
Partitions: 6
Replication Factor: 3
Retention: 30 days
Processing Layer: Parse, Normalize, Enrich
Raw logs from diverse sources need processing before they're useful for security analysis:
Parsing: Extract structured fields from various formats (JSON, syslog, custom formats). Use schema registries to manage parsers.
Normalization: Map source-specific field names to your common schema. Example:
userIdentity.arn → user.idactor.alternateId → user.emailUSER=jdoe → user.nameEnrichment: Add context not present in the original event:
Filtering/Routing: Send different events to different destinations:
Your processing pipeline is security-critical infrastructure. If it fails, you lose security visibility. Design for high availability with redundant processors, dead-letter queues for parsing failures, and comprehensive monitoring of pipeline health. A misconfigured parser that silently drops events can blind your security team for hours or days.
Security log storage presents unique challenges: you need fast queries for real-time detection, long retention for compliance and forensics, and massive scale as distributed systems generate billions of events daily. The solution is tiered storage with hot, warm, and cold layers.
Hot Storage (0-7 days): Optimized for query speed. Events here are actively searched during investigations and feed real-time alerting. Technologies: Elasticsearch, Splunk, ClickHouse.
Warm Storage (7-90 days): Optimized for cost-efficient querying. Accessed for investigations beyond immediate incidents. May use slower, cheaper storage tiers. Technologies: Elasticsearch frozen tier, S3 + query engines.
Cold Storage (90+ days): Optimized for retention cost. Rarely accessed but required for compliance or deep investigations. Technologies: S3 Glacier, Google Coldline, Azure Archive.
| Tier | Retention | Access Time | Query Speed | Cost/GB/Month | Use Case |
|---|---|---|---|---|---|
| Hot | 0-7 days | Instant | Sub-second | $0.50-1.00 | Real-time alerting, active investigations |
| Warm | 7-90 days | Seconds | Seconds-minutes | $0.10-0.30 | Recent incident investigation, trend analysis |
| Cold (Archive) | 90 days-7 years | Hours | Hours-days | $0.004-0.01 | Compliance retention, forensic investigations |
Retention Requirements by Regulation
Compliance requirements often dictate minimum retention periods:
Design your retention policy to meet the most stringent applicable requirement, but implement tiered storage to manage costs.
Log Integrity and Tamper Evidence
Security logs are only valuable if they're trustworthy. An attacker who gains system access often attempts to modify or delete logs to cover their tracks. Implement integrity controls:
Write-Once Storage: Use immutable storage (S3 Object Lock, WORM-compliant storage) for log archives. Once written, logs cannot be modified or deleted until retention expires.
Cryptographic Signing: Sign log entries or batches at the source. Any modification invalidates signatures.
Hash Chains: Create cryptographic chains linking log entries. Deletion or modification breaks the chain.
Third-Party Attestation: Forward copies to an independent system that can attest to what was received.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Log Entry 1 │───▶│ Log Entry 2 │───▶│ Log Entry 3 │
│ hash: abc123 │ │ prev: abc123 │ │ prev: def456 │
│ │ │ hash: def456 │ │ hash: ghi789 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
▲ ▲ ▲
│ │ │
Can't modify Can't delete Chain proves
without breaking without breaking completeness
hash chain hash chain
Storage costs dominate log platform expenses. Optimize by: (1) Filtering out known-low-value events before storage, (2) Using aggressive compression on cold storage, (3) Sampling high-volume, low-value events, (4) Storing parsed/normalized data rather than raw duplicates, (5) Right-sizing hot tier retention to actual investigation patterns.
Implementing security event logging in production requires careful attention to reliability, performance, and security. Here are battle-tested practices from organizations operating at scale:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
import { Request, Response, NextFunction } from 'express';import { v4 as uuidv4 } from 'uuid';import { securityLogger } from './security-logger'; // Patterns for sensitive data that should never be loggedconst SENSITIVE_PATTERNS = [ { regex: /password/i, replacement: '[REDACTED]' }, { regex: /authorization:s*bearers+[a-zA-Z0-9-_]+/gi, replacement: 'Authorization: Bearer [REDACTED]' }, { regex: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g, replacement: '[CARD_REDACTED]' }, { regex: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, replacement: '[EMAIL_REDACTED]' },]; function sanitize(data: unknown): unknown { if (typeof data === 'string') { return SENSITIVE_PATTERNS.reduce( (str, pattern) => str.replace(pattern.regex, pattern.replacement), data ); } if (typeof data === 'object' && data !== null) { const sanitized: Record<string, unknown> = {}; for (const [key, value] of Object.entries(data)) { if (SENSITIVE_PATTERNS.some(p => p.regex.test(key))) { sanitized[key] = '[REDACTED]'; } else { sanitized[key] = sanitize(value); } } return sanitized; } return data;} export function securityLoggingMiddleware(req: Request, res: Response, next: NextFunction) { // Ensure correlation ID exists const traceId = req.headers['x-trace-id'] as string || uuidv4(); req.headers['x-trace-id'] = traceId; res.setHeader('x-trace-id', traceId); const startTime = Date.now(); // Log request start securityLogger.info({ '@timestamp': new Date().toISOString(), 'event.category': 'web', 'event.type': 'access', 'event.action': 'request_start', 'trace.id': traceId, 'http.request.method': req.method, 'url.path': req.path, 'source.ip': req.ip || req.socket.remoteAddress, 'source.user_agent': sanitize(req.headers['user-agent']), 'user.id': (req as any).user?.id, 'user.name': sanitize((req as any).user?.name), }); // Capture response const originalSend = res.send; res.send = function(body) { const duration = Date.now() - startTime; securityLogger.info({ '@timestamp': new Date().toISOString(), 'event.category': 'web', 'event.type': 'access', 'event.action': 'request_end', 'event.outcome': res.statusCode >= 400 ? 'failure' : 'success', 'trace.id': traceId, 'http.request.method': req.method, 'url.path': req.path, 'http.response.status_code': res.statusCode, 'event.duration': duration * 1_000_000, // nanoseconds 'source.ip': req.ip || req.socket.remoteAddress, 'user.id': (req as any).user?.id, }); return originalSend.call(this, body); }; next();}Even experienced organizations make predictable mistakes when implementing security logging. Learn from these common anti-patterns:
Logs themselves can be attack vectors. Log injection attacks occur when user input ends up in logs—attackers can inject fake log entries, corrupt format, or exploit log parsing vulnerabilities (Log4Shell). Always sanitize user input before logging and use structured logging to prevent format manipulation.
Security event logging is the foundation upon which all other security monitoring capabilities are built. Without comprehensive, reliable, well-structured logs, detection becomes guessing, investigation becomes archeology, and compliance becomes hope.
What's Next:
With security event logging in place, the next step is using those logs to detect threats. The following page covers Intrusion Detection—how to analyze security events to identify attacks in progress, from signature-based detection to behavioral analysis and network-based approaches.
You now understand the principles and practices of security event logging. This foundation enables all subsequent security monitoring capabilities—detection, investigation, response, and compliance. The logs you capture today determine what threats you can find tomorrow.