GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reading Stack Driver Logging - java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment · Issue #2379 · googleapis/google-cloud-java

Reading Stack Driver Logging - java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment #2379

New issue
Copy link
New issue
Copy link
Closed
Closed
Reading Stack Driver Logging - java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment#2379
Copy link
Assignees
NagarajP
Labels
api: loggingIssues related to the Cloud Logging API.type: questionRequest for information or clarification. Not an issue.

Description

@NagarajP
NagarajP
opened on Aug 24, 2017
Issue body actions

Hi,
I am trying to read logs from Stack Driver Logging. I have logged into gccloud.
Below is my program to read:
`public class App
{
Logging logging = LoggingOptions.getDefaultInstance().getService();

public static void main( String[] args ){
    System.out.println( "Hello World!" );
    App obj = new App();
    obj.run();
}

private void run() {
	
    	try {
    		
    		LoggingOptions.Builder optionsBuilder = LoggingOptions.newBuilder();
    		logging = optionsBuilder.build().getService();

    		Page<LogEntry> entries = logging.listLogEntries(EntryListOption.filter("logName=projects/<<PROJECT_ID>>/logs/<<LOGNAME>>"));
    		for(LogEntry entry :entries.iterateAll()) {
    			System.out.println(entry.toString());
    		}
    	}catch(Exception ex) {
    		ex.printStackTrace();
    	}
}

}`

Getting below exception:

Hello World! Exception in thread "main" java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder. at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:240) at com.google.cloud.logging.LoggingOptions.<init>(LoggingOptions.java:102) at com.google.cloud.logging.LoggingOptions$Builder.build(LoggingOptions.java:96) at com.google.cloud.logging.LoggingOptions.getDefaultInstance(LoggingOptions.java:55)

Though Project Id is passed, still i am getting the above exception. Please suggest. Thanks

Activity

  1. michaelbausor commented on Aug 24, 2017

    @michaelbausor
    michaelbausor
    on Aug 24, 2017
    Contributor
    More actions

    This is happening because you are not setting the project ID on the LoggingOptions.Builder, and there is no default project id set in your environment.

    Try replacing the line creating the logging object with this:

    logging = optionsBuilder.setProjectId("<<PROJECT_ID>>").build().getService();
  2. michaelbausor
    added
    api: loggingIssues related to the Cloud Logging API.
    type: questionRequest for information or clarification. Not an issue.
    on Aug 24, 2017
  3. NagarajP commented on Aug 25, 2017

    @NagarajP
    NagarajP
    on Aug 25, 2017
    Author
    More actions

    Thanks @michaelbausor . This problem is solved now and ending up other issue(io.grpc.StatusRuntimeException: PERMISSION_DENIED: The request is missing a valid API key) . You want me to create to new issue for this problem?

    My updated Code is:
    `private void run() {
    try {

        		LoggingOptions.Builder optionsBuilder = LoggingOptions.newBuilder();
        		System.out.println("optionsBuilder:::"+optionsBuilder);
        		Logging logging = optionsBuilder.setProjectId("<<PROJECT_ID>>").build().getService();
        		System.out.println("logging:::"+logging);
        		
        		Page<LogEntry> entries = logging.listLogEntries(EntryListOption.filter("logName=projects/<<PROJECT_ID>>/logs/<<LOG NAME>>"));
        		System.out.println("entries:::"+entries);
    
        		for(LogEntry entry :entries.iterateAll()) {
        			System.out.println(entry.toString());
        		}
        	}catch(Exception ex) {
        		ex.printStackTrace();
        	}
    }` 
    
  4. michaelbausor commented on Aug 25, 2017

    @michaelbausor
    michaelbausor
    on Aug 25, 2017
    Contributor
    More actions

    @NagarajP We can try to solve it here, as it looks related.

    Have you tried running the following gcloud command:
    gcloud auth application-default login

    This will create the application default credentials file that will be used. If you have done this and are still getting the same error, I would check to make sure that whichever user account you are using has permission to write to the project you have set.

    Another option you could try is to create service account credentials for your project, and use them instead of the application default credentials.

  5. NagarajP commented on Aug 25, 2017

    @NagarajP
    NagarajP
    on Aug 25, 2017
    Author
    More actions

    Hi @michaelbausor , Thanks for your input. Could you please tell me what is the exact permission( or role/policy/access) i needed, so that i can read ( and request to admin to tag with my account)Stack Driver logging using my corporate account?

  6. michaelbausor commented on Aug 25, 2017

    @michaelbausor
    michaelbausor
    on Aug 25, 2017
    Contributor
    More actions

    Looking at the available roles under Logging, there are three that you might need, depending on what you need to do:

    • Logs viewer (you will definitely need this)
    • Private logs viewer (if you need to view logs containing private content)
    • Logs writer (if you need to write logs)
  7. NagarajP commented on Aug 29, 2017

    @NagarajP
    NagarajP
    on Aug 29, 2017
    Author
    More actions

    Thanks @michaelbausor . This issue got resolved now after associating proper permissions. Hence i will close this issue.

  8. NagarajP
    closed this as completedon Aug 29, 2017
  9. JustinBeckwith
    assigned
    NagarajP
    on Feb 1, 2021
  10. chingor13
    added a commit that references this issue on Feb 20, 2026

    chore(main): release 3.0.2-SNAPSHOT (#2379)

    c9d4068
  11. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore(main): release 2.35.3-SNAPSHOT (googleapis#2379)

    34c2e0b
  12. meltsufin
    added a commit that references this issue on May 8, 2026

    deps: update dependency com.google.cloud:sdk-platform-java-config to …

    e9ec6e0
  13. blakeli0
    added a commit that references this issue on Jun 3, 2026

    chore(main): release 1.87.0 (#13346)

    6ce7a49
  14. benjaminp
    added a commit that references this issue on Jul 13, 2026

    chore: Update generation configuration at Sun Oct 27 02:27:47 UTC 2024 (

    eae6cf7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @NagarajP
    NagarajP

Labels

api: loggingIssues related to the Cloud Logging API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.