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:erroris the most minimal level of logging, reporting only errorswarnwill log warnings and errorsinfologs errors, warnings and some additional information and is the default logging leveldebuggenerates 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.
log_level setting in its configuration file (or the equivalent environment variable).
| Tyk component | Config option | Environment variable | Default value if unset |
|---|---|---|---|
| Tyk Dashboard | Not Available | Not Available | info |
| Tyk Gateway | log_level | TYK_GW_LOGLEVEL | info |
| Tyk Pump | log_level | TYK_PMP_LOGLEVEL | info |
| Tyk MDCB | log_level | TYK_MDCB_LOGLEVEL | info |
| Tyk Developer Portal | logLevel | PORTAL_LOG_LEVEL | info |
Log Format
You can configure the format in which logs will be generated; it can be eithertext (default) or json (recommended).
- Text Format
- JSON Format
| Tyk component | Config option | Environment variable | Default value if unset |
|---|---|---|---|
Tyk Gateway (from v5.6.0) | log_format | TYK_GW_LOGFORMAT | text |
| Tyk Pump | log_format | TYK_PMP_LOG_FORMAT | text |
| Tyk Dashboard (System) | log_format | TYK_DB_LOGFORMAT | text |
| Tyk Dashboard (Audit) | audit.format | TYK_DB_AUDIT_FORMAT | text |
| Tyk MDCB | Not Available | Not Available | text |
| Tyk Developer Portal | LogFormat | PORTAL_LOG_FORMAT | prod (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. ExampleAccess Logs
Gateway Only 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 theTYK_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.
Default Template Example
- Configuration File
- Environment Variables
Configuration using
tyk.confCustom Template Example
- Configuration File
- Environment Variables
Configuration using
tyk.confPerformance 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 totrue, 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 totrue in your tyk.conf file or by setting the TYK_GW_TRACK404LOGS environment variable to true.
Example
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.- Sentry
- Logstash
- Graylog
- Syslog
To enable Sentry as a log aggregator, update these settings in both your
tyk.conf and your tyk_analytics.conf:-
use_sentry: Set this totrueto enable the Sentry logger, you must specify a Sentry DSN undersentry_code. -
sentry_code: The Sentry-assigned DSN (a kind of URL endpoint) that Tyk can send log data to.