Reference documentation and code samples for the Cloud Logging API class Google::Cloud::Logging::Metric.
Metric
A logs-basedGoogle Cloud
Monitoringmetric. A metric
is a measured value that can be used to assess a system. The basis of a
logs-based metric is the collection of log entries that match a logs
filter.
The client-assigned metric identifier. Metric identifiers are limited
to 1000 characters and can include only the following characters:A-Z,a-z,0-9, and the special characters_-.,+!*',()%/</code>. The
forward-slash character (/) denotes a hierarchy of name pieces, and
it cannot be the first character of the name.
require"google/cloud/logging"logging=Google::Cloud::Logging.newmetric=logging.metric"severe_errors"metric.filter="logName:syslog AND severity>=ERROR"metric.save
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Logging API - Class Google::Cloud::Logging::Metric (v2.6.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.6.0 (latest)](/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging-Metric)\n- [2.5.0](/ruby/docs/reference/google-cloud-logging/2.5.0/Google-Cloud-Logging-Metric)\n- [2.4.0](/ruby/docs/reference/google-cloud-logging/2.4.0/Google-Cloud-Logging-Metric)\n- [2.3.3](/ruby/docs/reference/google-cloud-logging/2.3.3/Google-Cloud-Logging-Metric)\n- [2.2.2](/ruby/docs/reference/google-cloud-logging/2.2.2/Google-Cloud-Logging-Metric) \nReference documentation and code samples for the Cloud Logging API class Google::Cloud::Logging::Metric.\n\nMetric\n------\n\nA logs-based [Google Cloud\nMonitoring](https://cloud.google.com/monitoring/docs) metric. A metric\nis a measured value that can be used to assess a system. The basis of a\nlogs-based metric is the collection of log entries that match a logs\nfilter. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\nmetric = logging.create_metric \"errors\", \"severity\u003e=ERROR\"\n```\n\nMethods\n-------\n\n### #delete\n\n def delete() -\u003e Boolean\n\nPermanently deletes the logs-based metric. \n**Returns**\n\n- (Boolean) --- Returns `true` if the metric was deleted.\n**Example** \n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\nmetric = logging.metric \"severe_errors\"\nmetric.delete\n```\n\n### #description\n\n def description()\n\nThe description of this metric, which is used in documentation.\n\n### #description=\n\n def description=(description)\n\nUpdates the description of this metric, which is used in\ndocumentation.\n\n### #filter\n\n def filter()\n\nAn [advanced logs\nfilter](https://cloud.google.com/logging/docs/view/advanced_filters).\n\n### #filter=\n\n def filter=(filter)\n\nUpdates the [advanced logs\nfilter](https://cloud.google.com/logging/docs/view/advanced_filters).\n\n### #name\n\n def name()\n\nThe client-assigned metric identifier. Metric identifiers are limited\nto 1000 characters and can include only the following characters:\n`A-Z`, `a-z`, `0-9`, and the special characters `_-.,+!*',()%/\u003c/code\u003e. The\nforward-slash character (``/``) denotes a hierarchy of name pieces, and\nit cannot be the first character of the name.`\n\n`\n`\n\n### #refresh!\n\n def refresh!()\n\n**Alias Of** : [#reload!](./Google-Cloud-Logging-Metric#Google__Cloud__Logging__Metric_reload!_instance_) \nReloads the logs-based metric with current data from the Logging\nservice.\n**Example** \n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\nmetric = logging.metric \"severe_errors\"\nmetric.filter = \"Unwanted value\"\nmetric.reload!\nmetric.filter #=\u003e \"logName:syslog\"\n```\n\n### #reload!\n\n def reload!()\n\n**Aliases**\n\n- [#refresh!](./Google-Cloud-Logging-Metric#Google__Cloud__Logging__Metric_refresh!_instance_) \nReloads the logs-based metric with current data from the Logging\nservice.\n**Example** \n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\nmetric = logging.metric \"severe_errors\"\nmetric.filter = \"Unwanted value\"\nmetric.reload!\nmetric.filter #=\u003e \"logName:syslog\"\n```\n\n### #save\n\n def save()\n\nUpdates the logs-based metric.\n**Example** \n\n```ruby\nrequire \"google/cloud/logging\"\n\nlogging = Google::Cloud::Logging.new\nmetric = logging.metric \"severe_errors\"\nmetric.filter = \"logName:syslog AND severity\u003e=ERROR\"\nmetric.save\n```"]]