Skip to main content
CDN logs provide detailed information about CDN operations, including request details, cache status, response codes, and client information. Logs are available for up to 3 days.
For complete log data and longer retention, use the Logs Uploader service.

List Logs

Retrieve CDN logs with filtering and pagination.
import (
    "context"
    "fmt"
    "log"

    "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
    "github.com/G-Core/gcore-go/packages/param"
)

params := cdn.LogListParams{
    From:         "2024-01-15T10:00:00Z",
    To:           "2024-01-15T16:00:00Z",
    ResourceIDEq: param.NewOpt[int64](123456),
    StatusGte:    param.NewOpt[int64](200),
    StatusLt:     param.NewOpt[int64](300),
    Limit:        param.NewOpt[int64](100),
}

logs, err := client.CDN.Logs.List(context.Background(), params)
if err != nil {
    log.Fatal(err)
}

for logs.Next() {
    entry := logs.Current()
    fmt.Printf("%d %s %s %d %s\n",
        entry.Timestamp,
        entry.Method,
        entry.Path,
        entry.Status,
        entry.CacheStatus,
    )
}
from
string
required
Start date and time (ISO 8601/RFC 3339 format, UTC). Example: 2024-01-15T10:00:00Z
to
string
required
End date and time (ISO 8601/RFC 3339 format, UTC). Maximum 6 hours from from
resource_id__eq
int64
Filter by exact CDN resource ID
cname__eq
string
Filter by exact CDN resource CNAME
cname__contains
string
Filter by partial CNAME match (minimum 3 characters)
client_ip__eq
string
Filter by exact client IP address
status__eq
int64
Filter by exact HTTP status code
status__gte
int64
Filter by status code greater than or equal to value
status__lt
int64
Filter by status code less than value
cache_status__eq
string
Filter by cache status: HIT, MISS, BYPASS, EXPIRED, STALE, PENDING, UPDATING, REVALIDATED, or -
method__eq
string
Filter by HTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, or TRACE
datacenter__eq
string
Filter by data center where the request was processed
limit
int64
Maximum number of log entries to return per page
offset
int64
Number of log entries to skip from the beginning
ordering
string
Sort results by fields. Prefix with - for descending order. Multiple values separated by comma.Available fields: timestamp, method, client_ip, status, size, cname, resource_id, cache_status, datacenterExample: -timestamp,status
fields
string
Comma-separated list of fields to return. If not specified, all fields are returned.Example: timestamp,path,status,cache_status

Response Fields

timestamp
int64
Unix timestamp when the request was made
resource_id
int64
CDN resource ID that served the request
cname
string
CDN resource custom domain
client_ip
string
IP address of the client that made the request
method
string
HTTP method used in the request
path
string
Requested URL path
status
int64
HTTP response status code
size
int64
Response size in bytes
cache_status
string
Cache status: HIT, MISS, BYPASS, EXPIRED, STALE, PENDING, UPDATING, REVALIDATED, or -
datacenter
string
Data center that processed the request
user_agent
string
Value of the User-Agent header
referer
string
Value of the Referer header
sent_http_content_type
string
MIME type of the transmitted resource (Content-Type header)
tcpinfo_rtt
int64
Round-trip time in microseconds for TCP transmission

Download Logs

Download logs as a compressed file for offline analysis.
params := cdn.LogDownloadParams{
    Format:       "csv",
    From:         "2024-01-15T10:00:00Z",
    To:           "2024-01-15T16:00:00Z",
    ResourceIDEq: param.NewOpt[int64](123456),
    StatusGte:    param.NewOpt[int64](200),
    StatusLt:     param.NewOpt[int64](300),
}

resp, err := client.CDN.Logs.Download(context.Background(), params)
if err != nil {
    log.Fatal(err)
}
defer resp.Body.Close()

// Save to file
out, err := os.Create("cdn-logs.zip")
if err != nil {
    log.Fatal(err)
}
defer out.Close()

_, err = io.Copy(out, resp.Body)
if err != nil {
    log.Fatal(err)
}

fmt.Println("Logs downloaded to cdn-logs.zip")
format
string
required
Output format: csv or tsv
from
string
required
Start date and time (ISO 8601 format, UTC)
to
string
required
End date and time (ISO 8601 format, UTC). Maximum 6 hours from from
sort
string
Sort order. Prefix with - for descending. Example: -timestamp,status
All filter parameters from the List method are also supported.

Filtering Examples

Filter by 2xx Status Codes

params := cdn.LogListParams{
    From:      "2024-01-15T10:00:00Z",
    To:        "2024-01-15T16:00:00Z",
    StatusGte: param.NewOpt[int64](200),
    StatusLt:  param.NewOpt[int64](300),
}

Filter by Multiple Cache Statuses

params := cdn.LogListParams{
    From:          "2024-01-15T10:00:00Z",
    To:            "2024-01-15T16:00:00Z",
    CacheStatusIn: param.NewOpt("HIT,MISS,EXPIRED"),
}

Filter by Client IP Range

params := cdn.LogListParams{
    From:       "2024-01-15T10:00:00Z",
    To:         "2024-01-15T16:00:00Z",
    ClientIPIn: param.NewOpt("192.168.1.1,192.168.1.2,10.0.0.1"),
}

Filter by HTTP Methods

params := cdn.LogListParams{
    From:     "2024-01-15T10:00:00Z",
    To:       "2024-01-15T16:00:00Z",
    MethodIn: param.NewOpt("POST,PUT,DELETE"),
}

Filter by Data Center

params := cdn.LogListParams{
    From:         "2024-01-15T10:00:00Z",
    To:           "2024-01-15T16:00:00Z",
    DatacenterIn: param.NewOpt("ams,fra,lon"),
}

Auto-Paging

Use auto-paging to iterate through all results automatically:
params := cdn.LogListParams{
    From:         "2024-01-15T10:00:00Z",
    To:           "2024-01-15T16:00:00Z",
    ResourceIDEq: param.NewOpt[int64](123456),
}

iter := client.CDN.Logs.ListAutoPaging(context.Background(), params)

for iter.Next() {
    entry := iter.Current()
    fmt.Printf("%d %s %s %d\n",
        entry.Timestamp,
        entry.Method,
        entry.Path,
        entry.Status,
    )
}

if err := iter.Err(); err != nil {
    log.Fatal(err)
}

Analysis Examples

Cache Hit Rate Analysis

params := cdn.LogListParams{
    From:         "2024-01-15T00:00:00Z",
    To:           "2024-01-15T23:59:59Z",
    ResourceIDEq: param.NewOpt[int64](123456),
}

iter := client.CDN.Logs.ListAutoPaging(context.Background(), params)

totalRequests := 0
cacheHits := 0

for iter.Next() {
    entry := iter.Current()
    totalRequests++
    if entry.CacheStatus == "HIT" {
        cacheHits++
    }
}

hitRate := float64(cacheHits) / float64(totalRequests) * 100
fmt.Printf("Cache hit rate: %.2f%% (%d hits / %d requests)\n",
    hitRate, cacheHits, totalRequests)

Top Client IPs

params := cdn.LogListParams{
    From: "2024-01-15T00:00:00Z",
    To:   "2024-01-15T23:59:59Z",
}

iter := client.CDN.Logs.ListAutoPaging(context.Background(), params)

ipCounts := make(map[string]int)

for iter.Next() {
    entry := iter.Current()
    ipCounts[entry.ClientIP]++
}

// Sort and display top IPs
type ipCount struct {
    ip    string
    count int
}

var sorted []ipCount
for ip, count := range ipCounts {
    sorted = append(sorted, ipCount{ip, count})
}

sort.Slice(sorted, func(i, j int) bool {
    return sorted[i].count > sorted[j].count
})

fmt.Println("Top 10 client IPs:")
for i := 0; i < 10 && i < len(sorted); i++ {
    fmt.Printf("%d. %s: %d requests\n", i+1, sorted[i].ip, sorted[i].count)
}

Bandwidth Usage

params := cdn.LogListParams{
    From:         "2024-01-15T00:00:00Z",
    To:           "2024-01-15T23:59:59Z",
    ResourceIDEq: param.NewOpt[int64](123456),
}

iter := client.CDN.Logs.ListAutoPaging(context.Background(), params)

var totalBytes int64

for iter.Next() {
    entry := iter.Current()
    totalBytes += entry.Size
}

totalMB := float64(totalBytes) / 1024 / 1024
totalGB := totalMB / 1024

fmt.Printf("Total bandwidth: %.2f GB (%.2f MB)\n", totalGB, totalMB)

Error Rate Analysis

params := cdn.LogListParams{
    From:         "2024-01-15T00:00:00Z",
    To:           "2024-01-15T23:59:59Z",
    ResourceIDEq: param.NewOpt[int64](123456),
}

iter := client.CDN.Logs.ListAutoPaging(context.Background(), params)

statusGroups := map[string]int{
    "2xx": 0,
    "3xx": 0,
    "4xx": 0,
    "5xx": 0,
}

totalRequests := 0

for iter.Next() {
    entry := iter.Current()
    totalRequests++
    
    switch {
    case entry.Status >= 200 && entry.Status < 300:
        statusGroups["2xx"]++
    case entry.Status >= 300 && entry.Status < 400:
        statusGroups["3xx"]++
    case entry.Status >= 400 && entry.Status < 500:
        statusGroups["4xx"]++
    case entry.Status >= 500 && entry.Status < 600:
        statusGroups["5xx"]++
    }
}

fmt.Printf("Status code distribution:\n")
for group, count := range statusGroups {
    percentage := float64(count) / float64(totalRequests) * 100
    fmt.Printf("%s: %d (%.2f%%)\n", group, count, percentage)
}

Best Practices

  1. Limit Time Range - Keep queries within 6 hours for faster results
  2. Use Filters - Apply filters to reduce data volume and improve performance
  3. Select Fields - Use the fields parameter to return only needed data
  4. Auto-Paging - Use ListAutoPaging for processing large result sets
  5. Download for Analysis - Download logs for complex offline analysis
  6. Monitor Cache - Regularly check cache hit rates to optimize performance

Limitations

  • Logs are available for up to 3 days
  • Time range cannot exceed 6 hours per query
  • Results are limited to prevent timeout (use pagination)
  • For historical data or complete logs, use Logs Uploader service

CDN Resources

Manage CDN resources generating logs

Statistics

View aggregated CDN statistics

Build docs developers (and LLMs) love