0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【GCP】ログエクスプローラーで正規表現を使ったフィルタリング

Posted at

TL;DR

検索クエリを入れるとき=~とすれば正規表現が使える。

key=~".*Qiita\d+"

本文

以下のような3つのログを出力していたとする。

{
	"apiName": "POST Regist",
	"jsonPayload": {
		"userName": "田中太郎",
		"message": "Message."
	},
	"labels": {
		"version": "1.0.0"
	}
}
{
	"apiName": "POST Login",
	"jsonPayload": {
		"userName": "山田花子",
		"message": "Message."
	},
	"labels": {
		"version": "1.0.1"
	}
}
{
	"apiName": "GET Info",
	"jsonPayload": {
		"userName": "田中花子",
		"message": "Message."
	},
	"labels": {
		"version": "2.0.0"
	}
}

以下の②の部分に正規表現のクエリが書ける。
クエリを実行(Run query)で実行。

スクリーンショット 2024-06-17 23.42.56.png

POSTという文字列を含むログを抽出

apiName=~"POST.*"

名前が花子さんだけ抽出

jsonPayload.userName=~".*花子"

versionが1.0.*のログだけ抽出

jsonPayloadのようなGCPで用意されているフィールド以外はkeyを指定して降りていくとき""で括る必要があるっぽい。
入力してるとlabelsの時点で補完してくれるので意識はしなくてもいいと思う。

labels."version"=~"^1\.0\.\d+$"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?