Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Writing to Cloud Logging fails with logging.logEntries.create denied

ErrorPermission '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.

  • Applies to Google Cloud Logging API v2, gcloud CLI
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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=yaml
  2. 2Match what you see, then jump to its fix

    1. 1The service account email is absent from roles/logging.logWriter in the policyThe service account does not have the Logs Writer roleFix
    2. 2The 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

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 logging

2Fix

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=None

3Verify

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.logWriter

Confirmed by docs.cloud.google.com

Did this fix it?

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=yaml

2Fix

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-log

3Verify

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.logWriter

Confirmed by docs.cloud.google.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.