TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.76k stars 1.09k forks source link

POC: Add ability to output logs in stdout #6600

Open titpetric opened 2 months ago

titpetric commented 2 months ago

This PR does:

  1. use log.SetFormatter intead of the no-mutex version, safe api use
  2. if TYK_LOGOUTPUT=stdout env is defined, the output goes to stdout

tested with:

# TYK_LOGOUTPUT=stdout ./tyk | head -n 1
time="Oct 02 18:32:06" level=info msg="Tyk API Gateway v5.5.0-dev" prefix=main
# git status .
On branch improvement/logging

Alternatively the same can be achieved with 2>&1, but that's hard to inject into the container, especially with distroless where there isn't a shell available.

Alternative options / extensions of our logging behaviour:

My immediate other thought was to configure syslog:

// Enable Syslog log output
UseSyslog bool `json:"use_syslog"`
// Syslong transport to use. Values: tcp or udp.
SyslogTransport string `json:"syslog_transport"`
// Graylog server address
SyslogNetworkAddr string `json:"syslog_network_addr"`

Discarded this idea quickly, as you'd actually have to have syslog in the distroless env. Syslog could be configured to log the output to file(s), but it seems as an unnecessary hop when you want to terminate the log data flow inside the container.