I am currently checking for an option to reduce Cloud SQL logging cost (Cloud Logging cost in GCP). Currently the Cloud SQL instance is writing millions of log entries in stackdriver per day. Out of this 99% of the entries are INFO level. How can I avoid the INFO level entries that Cloud SQL generates in Cloud Logging and make only entries above INFO to be logged? Is there a configuration that I can make at Cloud SQL level or at Cloud Logging Level?
You can control the Google Cloud SQL logging level via log_min_messages
.
Controls which message levels are written to the server log. Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level includes all the levels that follow it. The later the level, the fewer messages are sent to the log. The default is WARNING. Note that LOG has a different rank here than in client_min_messages. Only superusers and users with the appropriate SET privilege can change this setting.
I recommend changing database flags via the Google Cloud Console interface link.
This example uses the Google Cloud CLI:
gcloud sql instances patch INSTANCE_NAME --database-flags=log_min_messages=WARNING
This command will overwrite all database flags previously set. To keep those and add new ones, include the values for all flags you want set on the instance; any flag not specifically included is set to its default value. For flags that do not take a value, specify the flag name followed by an equals sign ("=").