Skip to main content
A log is a timestamped text record, either structured (recommended) or unstructured, with some metadata. Tyk logs are written to stderr and stdout. In a typical installation, these will be handled by the service manager running the process.

Types of Logs

Tyk generates three types of logs:
  • Application Logs: Captures internal events of the system, such as health-checks, status, configuration changes, and errors, which are typically used for monitoring and debugging.
  • Access Logs: Traditional server logs that record basic information about each request to your API Gateway. Gateway Only
  • 404 Logs: A configuration option in Tyk Gateway that enables logging of HTTP 404 (Not Found) errors. Gateway Only
Tyk Gateway also generates API Traffic Logs, which are written into Redis for detailed information about API traffic and analysis. For more information on API Traffic Logs, refer to this documentation.

Configuring Logs

You can configure log verbosity and format for the following Tyk components:

Log Verbosity

Tyk can generate application logs at four levels of verbosity:
  • error is the most minimal level of logging, reporting only errors
  • warn will log warnings and errors
  • info logs errors, warnings and some additional information and is the default logging level
  • debug generates a high volume of logs for maximum visibility of what Tyk is doing when you need to debug an issue
Debug log level generates a significant amount of data and is not recommended unless debugging.
You can set the logging verbosity for each Tyk Component using the appropriate log_level setting in its configuration file (or the equivalent environment variable).
Tyk componentConfig optionEnvironment variableDefault value if unset
Tyk DashboardNot AvailableNot Availableinfo
Tyk Gatewaylog_levelTYK_GW_LOGLEVELinfo
Tyk Pumplog_levelTYK_PMP_LOGLEVELinfo
Tyk MDCBlog_levelTYK_MDCB_LOGLEVELinfo
Tyk Developer PortallogLevelPORTAL_LOG_LEVELinfo

Log Format

You can configure the format in which logs will be generated; it can be either text (default) or json (recommended).
As a general performance tip, the json output format incurs less memory allocation overhead than the text format. For optimal performance, it’s recommended to configure logging in the JSON format.
time="Sep 05 09:04:12" level=info msg="Tyk API Gateway v5.6.0" prefix=main
Tyk componentConfig optionEnvironment variableDefault value if unset
Tyk Gateway (from v5.6.0)log_formatTYK_GW_LOGFORMATtext
Tyk Pumplog_formatTYK_PMP_LOG_FORMATtext
Tyk Dashboard (System)log_formatTYK_DB_LOGFORMATtext
Tyk Dashboard (Audit)audit.formatTYK_DB_AUDIT_FORMATtext
Tyk MDCBNot AvailableNot Availabletext
Tyk Developer PortalLogFormatPORTAL_LOG_FORMATprod (equivalent to json)

Application Logs

Application logs capture internal events of the system, such as health-checks, status, configuration changes, and errors, which are typically used for monitoring and debugging. Example
time="Feb 16 22:48:39" level=info msg="Using Policies from Dashboard Service" prefix=main
time="Feb 16 22:48:39" level=info msg="Calling dashboard service for policy list" prefix=policy
time="Feb 16 22:48:39" level=info msg="Processing policy list" prefix=policy
time="Feb 16 22:48:39" level=info msg="Policies found (5 total):" prefix=main

Access Logs

Gateway Only Not available in Tyk Cloud Access logs are simple, traditional server logs that record basic information about each request to your API Gateway and are written directly to stdout/stderr. As of Tyk Gateway v5.8.0, you can configure the Gateway to log individual API requests. To enable this feature, set the TYK_GW_ACCESSLOGS_ENABLED environment variable to true. You can also configure which fields are logged by configuring the TYK_GW_ANALYTICSLOGS_TEMPLATE environment variable. Below are the available values you can include:

Configurable Fields

api_key
Obfuscated or hashed API key used in the request.
client_ip
IP address of the client making the request.
host
Hostname of the request.
method
HTTP method used in the request (for example, GET or POST).
path
URL path of the request.
protocol
Protocol used in the request (for example, HTTP/1.1).
remote_addr
Remote address of the client.
upstream_addr
Full upstream address, including scheme, host, and path.
upstream_latency
Round-trip duration between the gateway sending the request to the upstream service and receiving the response.
latency_total
Total time taken to process the request, including upstream latency and additional gateway processing.
user_agent
User agent string provided by the client.
status
HTTP response status code.
trace_id
The OpenTelemetry trace ID for the request (32-character hex W3C trace ID). Only present when OpenTelemetry is enabled and a trace ID is available. Use this to navigate from an access log entry to the corresponding trace in your observability backend.
response_flag
Error classification code, only present on error requests. See Error Classification Fields.
response_code_details
Detailed error description in snake_case, only present on error requests.
error_source
Gateway component that generated the error, only present on error requests.
error_target
Upstream address for proxy errors, only present on error requests.
upstream_status
HTTP status from upstream for passthrough errors, only present when upstream responded.
tls_cert_expiry
TLS certificate expiration date in RFC 3339 format, only present on TLS certificate errors.
tls_cert_subject
TLS certificate subject (for example, CN=api.example.com), only present on TLS certificate errors.
circuit_breaker_state
Circuit breaker state (for example, OPEN), only present on circuit breaker errors.

Default Template Example

Configuration using tyk.conf
{
    "access_logs": {
        "enabled": true
    }
}
Output:
time="Jan 29 08:27:09" level=info api_id=b1a41c9a89984ffd7bb7d4e3c6844ded api_key=00000000 api_name=httpbin client_ip="::1" host="localhost:8080" latency_total=62 method=GET org_id=678e6771247d80fd2c435bf3 path=/get prefix=access-log protocol=HTTP/1.1 remote_addr="[::1]:63251" status=200 trace_id=4bf92f3577b34da6a3ce929d0e0e4736 upstream_addr="http://httpbin.org/get" upstream_latency=61 user_agent=PostmanRuntime/7.43.0

Custom Template Example

Configuration using tyk.conf
{
    "access_logs": {
        "enabled": true,
        "template": [
            "api_key",
            "remote_addr",
            "upstream_addr"
        ]
    }
}
Output:
time="Jan 29 08:27:48" level=info api_id=b1a41c9a89984ffd7bb7d4e3c6844ded api_key=00000000 api_name=httpbin org_id=678e6771247d80fd2c435bf3 prefix=access-log remote_addr="[::1]:63270" upstream_addr="http://httpbin.org/get"

Error Classification

Access logs automatically include structured error classification fields for failed requests. These fields help developers quickly identify root causes, such as TLS certificate expiry, connection refusal, rate limiting, or authentication errors—directly from the access log without cross referencing application or API Traffic Logs.
Error classification fields appear only when errors occur; successful requests do not include them.

Log Field Reference

FieldTypeDescriptionPresent when
response_flagString3-letter code identifying the error categoryAlways (on error)
response_code_detailsStringsnake_case description of the specific errorAlways (on error)
error_sourceStringGateway component where the error originatedAlways (on error)
error_targetStringUpstream address being accessedUpstream/proxy errors
upstream_statusIntegerHTTP status code returned by the upstreamUpstream responded with 5XX
tls_cert_expiryStringCertificate expiration date (RFC 3339)TLS certificate errors
tls_cert_subjectStringCertificate subject (e.g., CN=api.example.com)TLS certificate errors
circuit_breaker_stateStringState of the circuit breaker (e.g., OPEN)Circuit breaker errors
Fields with empty or zero values are omitted from the log entry rather than being set to empty strings or zero. This keeps successful request logs unchanged and error logs concise.

Response flags: Upstream and proxy errors (5XX)

These flags indicate errors occurring when the gateway proxies requests to the upstream service.
FlagNameHTTP StatusDescription
TLETLS Certificate Expired502The upstream server’s TLS certificate has expired
TLITLS Certificate Invalid502The upstream’s TLS certificate failed validation
TLMTLS Hostname Mismatch502The certificate’s CN/SAN does not match the hostname
TLNTLS Not Trusted502The certificate was issued by an unknown authority
TLHTLS Handshake Failure502The TLS handshake failed (bad certificate, client cert required)
TLPTLS Protocol Error502TLS protocol or version mismatch
TLATLS Alert502A TLS alert was received from the upstream
UCFConnection Refused502The upstream server refused the TCP connection
UCTConnection Timeout502The TCP connection to the upstream timed out
URRConnection Reset502The connection was reset by the upstream server
EPIBroken Pipe502The connection was closed unexpectedly (EPIPE)
URTResponse Timeout504The upstream did not respond within the timeout period
DNSDNS Resolution Failure502The upstream hostname could not be resolved
NRHNo Route to Host502The upstream host or network is unreachable
NHUNo Healthy Upstreams503All upstream targets in the load balancer are unhealthy
CBOCircuit Breaker Open503The circuit breaker is open
URSUpstream Response 5XX5XXThe upstream returned a 5XX status code
UPEUpstream Error5XXA generic upstream error that did not match a specific pattern

Response flags: Gateway errors (4XX)

These flags indicate errors within the gateway’s middleware pipeline before the request reaches the upstream. The error_source field identifies the middleware that rejected the request.
FlagNameHTTP StatusDescription
AMFAuth Field Missing400 or 401The authorization header or parameter is missing
AKIAPI Key Invalid403The API key was not found or is invalid
TKEToken Expired403The JWT, OAuth token, or client certificate has expired
TKIToken Invalid403The JWT or OAuth token is malformed or has an invalid signature
TCVToken Claims Invalid401JWT claims validation failed (e.g., issuer, audience, custom claims)
EADExternal Auth Denied403An external authentication service denied the request
The HTTP status code for AMF varies by middleware: Auth Token middleware returns 401, while OAuth2 and JWT middleware return 400. The response_flag is the same, but error_source identifies the middleware that generated the error.

Understanding error_source

The error_source field identifies the gateway component that generated the error, helping you locate where the failure occurred in the request processing pipeline.
error_sourceComponentTypical flags
ReverseProxyUpstream proxy and transport layerUCF, TLE, URT, DNS, CBO, NHU
UpstreamThe upstream server itself (responded with error)URS
AuthKeyAuth Token middlewareAMF, AKI, TKE
Oauth2KeyExistsOAuth2 middlewareAMF, AKI, EAD
JWTMiddlewareJWT middlewareAMF, TKI, TCV, TKE
BasicAuthMiddlewareBasic Auth middlewareAMF, IHD, BIV
RateLimitAndQuotaCheckRate limiting and quota middlewareRLT, QEX
APIRateLimitMiddlewareAPI-level rate limitingRLT
RequestSizeLimitMiddlewareRequest size limit middlewareBTL, CLM
ValidateJSONMiddlewareJSON schema validation middlewareBIV

Examples

When the upstream server refuses the TCP connection, the access log shows:
time="Feb 10 14:23:01" level=info api_id=abc123 api_name=my-api
  status=502 response_flag=UCF response_code_details=connection_refused
  error_source=ReverseProxy error_target=api.backend.com:443
  method=GET path=/users prefix=access-log
Key fields:
  • response_flag=UCF identifies the error as an Upstream Connection Failure.
  • error_target=api.backend.com:443 shows the specific upstream that refused the connection.
  • upstream_status is absent because no HTTP response was received from the upstream.
When the upstream’s TLS certificate has expired:
time="Feb 10 14:25:33" level=info api_id=abc123 api_name=my-api
  status=502 response_flag=TLE response_code_details=tls_certificate_expired
  error_source=ReverseProxy error_target=api.backend.com:443
  tls_cert_expiry=2024-01-15T00:00:00Z tls_cert_subject="CN=api.backend.com"
  method=GET path=/users prefix=access-log
The tls_cert_expiry and tls_cert_subject fields help you identify exactly which certificate needs renewal and when it expired.
When a circuit breaker trips for an endpoint, the access log shows:
time="Feb 10 14:30:00" level=info api_id=abc123 api_name=my-api
  status=503 response_flag=CBO response_code_details=circuit_breaker_open
  error_source=ReverseProxy error_target=api.backend.com:443/health
  circuit_breaker_state=OPEN
  method=GET path=/health prefix=access-log
When a client exceeds the configured rate limit, the access log shows:
time="Feb 10 14:31:22" level=info api_id=abc123 api_name=my-api
  status=429 response_flag=RLT response_code_details=session_rate_limited
  error_source=RateLimitAndQuotaCheck
  method=POST path=/orders prefix=access-log
Note that error_target is absent for gateway-level errors (authentication, rate limiting, validation) because the request did not reach the upstream.
When the upstream receives the request but responds with an error status, the access log shows:
time="Feb 10 14:32:45" level=info api_id=abc123 api_name=my-api
  status=503 response_flag=URS response_code_details=upstream_response_5xx
  error_source=Upstream error_target=api.backend.com:443
  upstream_status=503
  method=GET path=/health prefix=access-log
Key distinction: error_source=Upstream and upstream_status=503 indicate that the upstream returned an error, unlike a connection failure, where no response was received.

Performance Considerations

Enabling access logs introduces some performance overhead:
  • Latency: Increases consistently by approximately 4%–13%, depending on CPU allocation and configuration.
  • Memory Usage: Memory consumption increases by approximately 6%–7%.
  • Allocations: The number of memory allocations increases by approximately 5%–6%.
While the overhead of enabling access logs is noticeable, the impact is relatively modest. These findings suggest the performance trade-off may be acceptable depending on the criticality of logging to your application.

track_404_logs

Gateway Only The track_404_logs is a configuration in Tyk Gateway. When you set it to true, the gateway will log all incoming HTTP requests that result in a 404 Not Found error because they don’t match any of your configured API listen paths.
Currently, users can track 404 traffic through the gateway only using this method. Access logs and Tyk Pump’s API traffic logs do not include 404 traffic.

Configuration

You can enable this feature by setting the track_404_logs option to true in your tyk.conf file or by setting the TYK_GW_TRACK404LOGS environment variable to true. Example
time="2023-07-15T10:25:30Z" level=error msg="Not Found" prefix=gateway request="GET /nonexistent/path HTTP/1.1" origin=192.168.1.5:54321

Register Custom Log Handlers

Gateway Only Custom logging event handlers can be registered against Gateway events to customise the logs that are generated for those events.

Exporting Logs

Gateway Only Tyk Gateway can be configured to send log data to a range of 3rd party tools for aggregation and analysis.
To enable Sentry as a log aggregator, update these settings in both your tyk.conf and your tyk_analytics.conf:
  • use_sentry: Set this to true to enable the Sentry logger, you must specify a Sentry DSN under sentry_code.
  • sentry_code: The Sentry-assigned DSN (a kind of URL endpoint) that Tyk can send log data to.

Troubleshooting

A common troubleshooting question is whether the upstream received the request or if the connection itself failed. The error classification fields make this distinction clear:
Scenarioerror_sourceupstream_statuserror_targetExample flags
Connection failed (upstream never received request)ReverseProxyabsent (0)presentUCF, UCT, DNS, TLE
Upstream responded with errorUpstreampresent (e.g., 503)presentURS
Gateway rejected request (never proxied)middleware nameabsentabsentRLT, AMF, BTL