The instructions here:
... specify recommendations for how best to ingest logs.
The current implementation is a good default for unknown environments and for GCE when the ops agent is absent.
It would be good to augment with an additional implementation for outputting structured logs to a file (or to stdout/stderr), with logic to select which implementation to use, with CloudLoggingExporter selecting which implementation to use based on constructor arguments, environment variables, and environment detection.
For example, if client is supplied and client is a LoggingV2Client, then it should always use the implementation based on writing directly to the Cloud Logging API. If nothing is supplied, the metadata.google.internal service endpoint is available, and the file /etc/google-cloud-ops-agent exists, then it would be ideal to select the implementation based on structured log files.