logger: Add command line option to escape c-style escape sequences in application logs (#8672)

Currently, application logs are not sanitized of c-style escape sequences. If any filter logs a message that contains newline characters, the logs will be printed to a new line. This breaks log formats set by the --log-format option, breaking integration with log viewers.

This change adds a command line option --log-format-escaped to escape c-style escape characters in application logs before they are outputted. Enabling this flag ensures newline characters in logs are ignored, meaning that each call to ENVOY_LOG will result in at most 1 line outputted. This flag works for both Stderr and File loggers.

Risk Level: Low

Testing:

Unit tests
Fuzz test
Manual verification (see comments in PR)
Performance Impact: As long as production environments are running with the default log level, this will only slightly impact startup time (only when --log-format-escaped is set). The critical section for each request/response will not be impacted.

Docs Changes: Added docs to command line options about new flag and possible use cases, like Stackdriver Logging integration on GKE.

Release Notes: Added release notes about new flag

Fixes #8637

Signed-off-by: Teju Nareddy <nareddyt@google.com>

Mirrored from https://github.com/envoyproxy/envoy @ 20ca0ae3bdd9c2a69194203f5e1d2eca92ce2b48
master-ci-test
data-plane-api(CircleCI) 6 years ago
parent 9c76d78795
commit 42dcb6bae9
  1. 5
      envoy/admin/v2alpha/server_info.proto
  2. 5
      envoy/admin/v3alpha/server_info.proto

@ -47,7 +47,7 @@ message ServerInfo {
CommandLineOptions command_line_options = 6; CommandLineOptions command_line_options = 6;
} }
// [#next-free-field: 27] // [#next-free-field: 28]
message CommandLineOptions { message CommandLineOptions {
enum IpVersion { enum IpVersion {
v4 = 0; v4 = 0;
@ -100,6 +100,9 @@ message CommandLineOptions {
// See :option:`--log-format` for details. // See :option:`--log-format` for details.
string log_format = 10; string log_format = 10;
// See :option:`--log-format-escaped` for details.
bool log_format_escaped = 27;
// See :option:`--log-path` for details. // See :option:`--log-path` for details.
string log_path = 11; string log_path = 11;

@ -47,7 +47,7 @@ message ServerInfo {
CommandLineOptions command_line_options = 6; CommandLineOptions command_line_options = 6;
} }
// [#next-free-field: 27] // [#next-free-field: 28]
message CommandLineOptions { message CommandLineOptions {
enum IpVersion { enum IpVersion {
v4 = 0; v4 = 0;
@ -102,6 +102,9 @@ message CommandLineOptions {
// See :option:`--log-format` for details. // See :option:`--log-format` for details.
string log_format = 10; string log_format = 10;
// See :option:`--log-format-escaped` for details.
bool log_format_escaped = 27;
// See :option:`--log-path` for details. // See :option:`--log-path` for details.
string log_path = 11; string log_path = 11;

Loading…
Cancel
Save