Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Docs
Launch GraphOS Studio

Logging in the Apollo Router


The Apollo accepts a command-line to set its log level:

NameDescription
--log

The log level, indicating the most severe log message type to include. In ascending order of verbosity, can be one of: off, error, warn, info, debug, or trace.

The default value is info.

The also accepts both RUST_LOG and APOLLO_ROUTER_LOG environment s with the same possible values as the command-line . The precedence is as follows (top to bottom):

  • RUST_LOG
  • command-line
  • APOLLO__LOG

RUST_LOG is supported for advanced users with specific filtering requirements who may wish to see log messages from crates consumed by the . Most users should use the command-line or APOLLO_ROUTER_LOG. Both of these options constrain log output to the router.

To be clear:

RUST_LOG=apollo_router::debug
APOLLO_ROUTER_LOG=debug
--log=debug

are equivalent, as are:

RUST_LOG=hyper=debug,apollo_router::info,h2=trace
APOLLO_ROUTER_LOG=hyper=debug,info,h2=trace
--log=hyper=debug,info,h2=trace

In both examples, the actual filter used by the is as defined in the RUST_LOG entry.

For more information about specifying filters for more granular control over Apollo logging, see the Env Logger documentation.

Output formats

The Apollo supports two logging formats:

The uses basic logging whenever an interactive shell session is attached, and it uses JSON-formatted logging otherwise (e.g., in CI and deployed environments). You can also enforce a specific format in configuration.

Basic logging via shell

Basic logging is mostly used during local development:

2022-03-18T10:28:11.090054Z INFO apollo_router::executable: apollo-router@0.1.0-alpha.9
2022-03-18T10:28:11.160650Z INFO apollo_router: Starting Apollo Router
2022-03-18T10:28:11.339906Z INFO apollo_router: Listening on http://127.0.0.1:4000 🚀

JSON-formatted logging

JSON-formatted logging provides compatibility with common searchable logging tools like Google Cloud Logging. The Apollo uses the popular Bunyan format:

{"timestamp":"2022-03-18T11:46:41.926942Z","level":"INFO","fields":{"message":"apollo-router@0.1.0-alpha.9"},"target":"apollo_router::executable"}
{"timestamp":"2022-03-18T11:46:41.985121Z","level":"INFO","fields":{"message":"Starting Apollo Router"},"target":"apollo_router"}
{"timestamp":"2022-03-18T11:46:42.171173Z","level":"INFO","fields":{"message":"Listening on http://127.0.0.1:4000 🚀"},"target":"apollo_router"}
{"timestamp":"2022-03-18T11:46:43.453993Z","level":"INFO","fields":{"message":"Stopped"},"target":"apollo_router"}

Basic configuration

This is part of an experimental feature, it means any time until it's stabilized (without the prefix experimental_) we might change the configuration shape or adding/removing features. If you want to give feedback or participate in that feature feel free to join this discussion on GitHub.

By default, the doesn't log certain values that might contain sensitive data, even if a sufficient log level is set:

  • Request bodies
  • Response bodies
  • Headers

You can enable selective logging of these values via the when_header option:

router.yaml
telemetry:
experimental_logging:
format: json # By default it's "pretty" if you are in an interactive shell session
display_filename: true # Display filename where the log is coming from. Default: true
display_line_number: false # Display line number in the file where the log is coming from. Default: true
# If one of these headers matches we will log supergraph and subgraphs requests/responses
when_header:
- name: apollo-router-log-request
value: my_client
headers: true # default: false
body: true # default: false
# log request for all requests coming from Iphones
- name: user-agent
match: ^Mozilla/5.0 (iPhone*
headers: true
Previous
Distributed caching
Next
Subgraph error inclusion
Edit on GitHubEditForumsDiscord