> ## Documentation Index
> Fetch the complete documentation index at: https://docs.drdroid.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing Log Queries

Search and analyze logs from various sources to debug issues and monitor your systems.

## Supported Log Sources

* Loki
* Elasticsearch
* CloudWatch Logs
* Google Cloud Logging
* Azure Monitor Logs
* Signoz

## Query Syntax

### Loki (LogQL)

```logql theme={null}
# Basic log line filter
{app="api"} |= "error"

# Parse and extract fields
{app="nginx"} | json | status >= 500

# Calculate rates
sum(rate({app="api"} |~ "error" [5m])) by (pod)
```

### Elasticsearch (KQL)

```kql theme={null}
# Basic search
kubernetes.container.name: "api" and message: "error"

# Time range
@timestamp >= now-15m and @timestamp <= now()
```

## Examples

### Error Patterns

```logql theme={null}
# Find errors with stack traces
{app="backend"} |~ "(?i)error|exception|fail"
```

### Performance Issues

```logql theme={null}
# Slow API responses
{app="api"} | json | duration > 1000
```

## Best Practices

* Use specific labels/tags to filter logs
* Leverage parsing to extract structured data
* Use time ranges to limit result sets
* Create alerts for recurring error patterns
* Use log sampling for high-volume logs
