Skip to content

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

Description

@NagarajP

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

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

Metadata

Metadata

Assignees

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