How to see the logs if we have deployed our Spring Boot Application in Google Cloud Platform?
We have developed a Spring Boot application and deployed in Google Cloud Platform (GCP). It is Compute Engine and we have Ubuntu 16.04.5 LTS
as Operating System and Apache Tomcat 8.5.3
as Web Server.
In this application, we have used System.out.println() statements and sometimes we are throwing the exceptions as well.
Now I want to see the logs which are generated by either
System.out.println()
or through theExceptions
but how to see the console inGoogle Cloud Platform
?
java spring tomcat google-cloud-platform ubuntu-16.04
add a comment |
We have developed a Spring Boot application and deployed in Google Cloud Platform (GCP). It is Compute Engine and we have Ubuntu 16.04.5 LTS
as Operating System and Apache Tomcat 8.5.3
as Web Server.
In this application, we have used System.out.println() statements and sometimes we are throwing the exceptions as well.
Now I want to see the logs which are generated by either
System.out.println()
or through theExceptions
but how to see the console inGoogle Cloud Platform
?
java spring tomcat google-cloud-platform ubuntu-16.04
add a comment |
We have developed a Spring Boot application and deployed in Google Cloud Platform (GCP). It is Compute Engine and we have Ubuntu 16.04.5 LTS
as Operating System and Apache Tomcat 8.5.3
as Web Server.
In this application, we have used System.out.println() statements and sometimes we are throwing the exceptions as well.
Now I want to see the logs which are generated by either
System.out.println()
or through theExceptions
but how to see the console inGoogle Cloud Platform
?
java spring tomcat google-cloud-platform ubuntu-16.04
We have developed a Spring Boot application and deployed in Google Cloud Platform (GCP). It is Compute Engine and we have Ubuntu 16.04.5 LTS
as Operating System and Apache Tomcat 8.5.3
as Web Server.
In this application, we have used System.out.println() statements and sometimes we are throwing the exceptions as well.
Now I want to see the logs which are generated by either
System.out.println()
or through theExceptions
but how to see the console inGoogle Cloud Platform
?
java spring tomcat google-cloud-platform ubuntu-16.04
java spring tomcat google-cloud-platform ubuntu-16.04
asked Nov 20 '18 at 17:26
AltafAltaf
3610
3610
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You cannot see the logs in GCP directly via System.out.println
or Exceptions
There are two ways to achieve this:
Possible but not recommended: Use filewriter to write logs into a file, access the file and read it
Recommended: Add logger into your application.
For this, include apache commons logging into your application's pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Write logs as per requirement:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}
You can use Logger into as many functions and as many controllers you like, it will be added to the same Logger and will be displayed collaboratively.
Now you will be able to see logs in your GCP's project Log tab :)
P.S. This will file log as info. You can use error or other classification options available to classify your log message type. For that, replace info with any following options to classify:
Any log level will display all types of logs.
Suppose, I have 30 Controllers then do I need to write this lineprivate static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?
– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.ExampleController.class
will get replaced by<ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398359%2fhow-to-see-the-logs-if-we-have-deployed-our-spring-boot-application-in-google-cl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You cannot see the logs in GCP directly via System.out.println
or Exceptions
There are two ways to achieve this:
Possible but not recommended: Use filewriter to write logs into a file, access the file and read it
Recommended: Add logger into your application.
For this, include apache commons logging into your application's pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Write logs as per requirement:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}
You can use Logger into as many functions and as many controllers you like, it will be added to the same Logger and will be displayed collaboratively.
Now you will be able to see logs in your GCP's project Log tab :)
P.S. This will file log as info. You can use error or other classification options available to classify your log message type. For that, replace info with any following options to classify:
Any log level will display all types of logs.
Suppose, I have 30 Controllers then do I need to write this lineprivate static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?
– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.ExampleController.class
will get replaced by<ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
add a comment |
You cannot see the logs in GCP directly via System.out.println
or Exceptions
There are two ways to achieve this:
Possible but not recommended: Use filewriter to write logs into a file, access the file and read it
Recommended: Add logger into your application.
For this, include apache commons logging into your application's pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Write logs as per requirement:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}
You can use Logger into as many functions and as many controllers you like, it will be added to the same Logger and will be displayed collaboratively.
Now you will be able to see logs in your GCP's project Log tab :)
P.S. This will file log as info. You can use error or other classification options available to classify your log message type. For that, replace info with any following options to classify:
Any log level will display all types of logs.
Suppose, I have 30 Controllers then do I need to write this lineprivate static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?
– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.ExampleController.class
will get replaced by<ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
add a comment |
You cannot see the logs in GCP directly via System.out.println
or Exceptions
There are two ways to achieve this:
Possible but not recommended: Use filewriter to write logs into a file, access the file and read it
Recommended: Add logger into your application.
For this, include apache commons logging into your application's pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Write logs as per requirement:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}
You can use Logger into as many functions and as many controllers you like, it will be added to the same Logger and will be displayed collaboratively.
Now you will be able to see logs in your GCP's project Log tab :)
P.S. This will file log as info. You can use error or other classification options available to classify your log message type. For that, replace info with any following options to classify:
Any log level will display all types of logs.
You cannot see the logs in GCP directly via System.out.println
or Exceptions
There are two ways to achieve this:
Possible but not recommended: Use filewriter to write logs into a file, access the file and read it
Recommended: Add logger into your application.
For this, include apache commons logging into your application's pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
Write logs as per requirement:
@RestController
public class ExampleController {
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
@RequestMapping("/<custom-url>")
public String function() {
String message = "Example message written to the log";
String secondMessage = "Second example written to the log";
LOGGER.info(message);
LOGGER.info(secondMessage);
return message;
}
}
You can use Logger into as many functions and as many controllers you like, it will be added to the same Logger and will be displayed collaboratively.
Now you will be able to see logs in your GCP's project Log tab :)
P.S. This will file log as info. You can use error or other classification options available to classify your log message type. For that, replace info with any following options to classify:
Any log level will display all types of logs.
answered Nov 20 '18 at 17:53
Abhishek AnandAbhishek Anand
1366
1366
Suppose, I have 30 Controllers then do I need to write this lineprivate static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?
– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.ExampleController.class
will get replaced by<ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
add a comment |
Suppose, I have 30 Controllers then do I need to write this lineprivate static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?
– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.ExampleController.class
will get replaced by<ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
Suppose, I have 30 Controllers then do I need to write this line
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?– Altaf
Nov 21 '18 at 4:33
Suppose, I have 30 Controllers then do I need to write this line
private static final Log LOGGER = LogFactory.getLog(ExampleController.class);
in all the Controllers?– Altaf
Nov 21 '18 at 4:33
Yes, you will need to . Just the classname would change. E.g.
ExampleController.class
will get replaced by <ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
Yes, you will need to . Just the classname would change. E.g.
ExampleController.class
will get replaced by <ControllerClassName>.class
– Abhishek Anand
Nov 22 '18 at 4:26
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
I have used Apache Commons Logging but how to see the logs in Compute Engine google cloud platform. Please reply
– Altaf
Nov 22 '18 at 12:35
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
in the gcp console, when you log in to project, you can find logger in the menu as this: imgur.com/a/z0oCn5c
– Abhishek Anand
Nov 23 '18 at 19:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398359%2fhow-to-see-the-logs-if-we-have-deployed-our-spring-boot-application-in-google-cl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown