Environment Variables
A number of environment variables can be used to configure the behavior of the library. There are also functions to configure this behavior in code. The environment variables are convenient when troubleshooting problems.
Setting the Default Project
Some of the GCS APIs need a project as a parameter. For such APIs the application can (a) call an overload that takes the project id as a parameter, (b) define the project explicitly when the Client
object is constructed, or (c) set the GOOGLE_CLOUD_PROJECT
environment variable to the desired project id. If you have set this environment variable the code can be even simpler:
namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name) {
StatusOr<gcs::BucketMetadata> bucket_metadata =
client.CreateBucket(bucket_name, gcs::BucketMetadata());
if (!bucket_metadata) throw std::move(bucket_metadata).status();
std::cout << "Bucket " << bucket_metadata->name() << " created."
<< "\nFull Metadata: " << *bucket_metadata << "\n";
}
See Also
google::cloud::storage::ProjectIdOption
Endpoint Overrides
CLOUD_STORAGE_EMULATOR_ENDPOINT=...
: override the default endpoint used by the library. Intended for testing only.
CLOUD_STORAGE_TESTBENCH_ENDPOINT=...
: DEPRECATED please use CLOUD_STORAGE_EMULATOR_ENDPOINT
instead.
See Also
google::cloud::storage::RestEndpointOption
See Also
google::cloud::storage::IamEndpointOption
Enabling Experimental Behaviors
GOOGLE_CLOUD_CPP_STORAGE_REST_CONFIG=...
: configuration for the REST protocol, but currently unused.
GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG=...
: this is deprecated.
Logging
CLOUD_STORAGE_ENABLE_TRACING=raw-client
: enables logging for each "RPC" generated by the library. Unless you have configured your own logging backend, you should also set GOOGLE_CLOUD_CPP_ENABLE_CLOG
to produce any output on the program's console.
CLOUD_STORAGE_ENABLE_TRACING=http
: enables logging for the full http traffic generated by the library.
CLOUD_STORAGE_ENABLE_TRACING=raw-client,http
: enables all logging.
See Also
google::cloud::GrpcTracingOptionsOption
GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes
: turns on logging in the library, basically the library always "logs" but the logging infrastructure has no backend to actually print anything until the application sets a backend or they set this environment variable.