Writing to Cloud Logging fails with logging.logEntries.create denied
Permission 'logging.logEntries.create' denied on resource (or it may not exist).Short answer
Writing a log entry needs the logging.logEntries.create permission on the project that receives it. The predefined Logs Writer role includes it. Find which identity your app really uses, grant it that role on the right project, and check the logName points at that same project.
Fix it fast
1Find out which cause you have
Read the policy of the project that should receive the logs and look for the service account your app runs as.
gcloud projects get-iam-policy PROJECT_ID --format=yaml2Match what you see, then jump to its fix
- 1
The service account email is absent from roles/logging.logWriter in the policyThe service account does not have the Logs Writer roleFix - 2
The role is present on one project, but the entries are addressed to another or to a project ID that does not existThe log name points at a different project than the one you grantedFix
- 1
What does the error look like?
Permission 'logging.logEntries.create' denied on resource (or it may not exist).
Cause 1 of 2
The service account does not have the Logs Writer role
1Check
Writing needs logging.logEntries.create on each project that receives entries. Logs Writer and Logging Admin include it.
gcloud projects get-iam-policy PROJECT_ID --format=yaml | grep -B3 -A3 logging2Fix
Grant Logs Writer to the service account on the project.
gcloud projects add-iam-policy-binding PROJECT_ID \
--member=serviceAccount:SA_EMAIL --role=roles/logging.logWriter \
--condition=None3Verify
The policy now lists the account under roles/logging.logWriter. Write one entry again.
gcloud projects get-iam-policy PROJECT_ID --format=yaml | grep -B3 logging.logWriterConfirmed by docs.cloud.google.com
Cause 2 of 2
The log name points at a different project than the one you granted
1Check
A logName has the form projects/[PROJECT_ID]/logs/[LOG_ID], and the caller needs the permission on that project. A mistyped project ID or a name from another environment fails the same way.
gcloud projects get-iam-policy PROJECT_ID --format=yaml2Fix
Use the right project ID in the logName and the client, or grant the role on the project that really receives the logs.
projects/PROJECT_ID/logs/my-app-log3Verify
Check that the account holds the role on that exact project, then send one entry from the app.
gcloud projects get-iam-policy PROJECT_ID --format=yaml | grep -B3 logging.logWriterConfirmed by docs.cloud.google.com
How do I stop it coming back?
- Give each environment its own service account and grant Logs Writer to that account only.
- Keep the project ID in configuration, not in code, so a log name cannot point at the wrong project.
- Grant only the Logs Writer role for logging, not a broad owner or editor role.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Back end
Google Cloud denies iam.serviceAccounts.getAccessToken when impersonating a service account
Permission 'iam.serviceAccounts.getAccessToken' denied on resource
This error appears when you or your app impersonate a service account without the right to create tokens for it.
2 causes, each with a fixBack end
Airflow SSHOperator stops a long script with SSH command timed out
airflow.exceptions.AirflowException: SSH command timed out
SSHOperator waits only 10 seconds for a command by default.
3 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fix