user1403505
user1403505

Reputation: 1005

Log entries api not retrieving log entries

I am trying to retrieve custom logs for a particular project in google-cloud. I am using this api:

https://logging.googleapis.com/v2/entries:list 

as per the example given in this link.

The below is the payload:

{
  "filter": "projects/projectA/logs/slow_log",
 
  "resourceNames": [
    "projects/projectA"
  ]
}

There is a custom log based metric called slow_log I created in that projectA, which gathers query logs from cloud-SQL database in that project. I also generated data before calling this api. I am able to see the data in stack-driver console, but unable to get it from the rest call.

Every time I run this api, I only get this response and nothing else:

  "nextPageToken": "EAA4suKu3qnLwbtrSg8iDSIDCgEAKgYIgL7q8wVSBwibvMSMvhhglPDiiJzdjt_zAWocCgwI2buKhAYQlvTd2gESCAgLEMPV7ukCGAAgAQ"
  1. Is there anything missing here?

  2. How is it possible to pass time range in this query?

Update

Changed the request as per the comment below as gave the full path of the logs: still only the token is displayed

{
  "filter": "projects/projectA/logs/cloudsql.googleapis.com%2Fmysql-slow.log",
  "projectIds": [
    "projectA"
  ],
  "orderBy": "timestamp desc"
}

Also I give this command from command line:

gcloud logging read logName="projects/projectA/logs/cloudsql.googleapis.com%2Fmysql-slow.log"

then it fetches the logs in command line, so I am not sure what I am missing in the api explorer and postman where I get only nextpage token.

Upvotes: 1

Views: 1621

Answers (2)

user27692387
user27692387

Reputation: 1

I can also confirm that API gave the response after adding all the 3 parameters in the request body. Created a lot of confusion and time for me to debug since it was giving null/empty response. After adding the order by clause, it worked for me.

Upvotes: 0

Sergiusz
Sergiusz

Reputation: 1245

resourceNames, filter and orderBy are mandatory, try like this:

{
  "resourceNames": [
    "projects/projectA"
  ],
  "filter": "projects/projectA/logs/cloudsql.googleapis.com%2Fmysql-slow.log",
  "orderBy": "timestamp desc"
}

Upvotes: 3

Related Questions