I though about "hiding" logger initialization, and return a normal logger (log
) from it when running the code in development environment, and a cloud.google.com/go/logging
one when deployed on GCP.
But cloud.google.com/go/logging
logger does not have the same interface as log
, so it would need some extra wrapping and I hope I can avoid that
Looking at the documentation, I can't find a standard way to do this. If there is no way to do it, what's the common approach to avoid spamming google cloud logging with logs not coming from preproduction/production environment ? Aside from making the logs noisy, logs ingestion have a cost I would like to avoid in some situations
CodePudding user response:
To recap the comments:
Google Cloud allows creating exclusion filters for Sinks.
According to Google docs:
you can choose to export your logs to BigQuery, Cloud Storage or Cloud Pub/Sub without needing to pay to ingest them into Stackdriver. You can even use exclusion filters to collect a percentage of logs, such as 1% of successful HTTP responses.
Additionally, note that the first 50 GiB of logs per project per month are free 1.
First 30 days of storage in the Log buckets are also free.
CodePudding user response:
In addition to the @Sergiusz answer, you can log your development into the same log or logs with the templated name and use logadmin package to delete the log(s) by the name. You can do it at the end of execution, in scheduled process or from a command line. You can do it also using gcloud logging logs delete
command. If you have multiple logs you will need to call "delete" multiple times per log.
However, I would recommend to mock the package instead because, using it may exhaust your API quota on the development project. So, if writing logs to STDOUT is sufficient, the fastest approach would be just to mock the Logger type.
P.S. I would recommend to open an issue in https://github.com/googleapis/google-cloud-go with your use case and ask for the change. It might lead to the breaking change though, but it is still important to provide the feedback.