In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to use SLF4J to log Java programs in a cloud environment. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.
I developed a Java application, deployed it to the cloud, tested it with postman and found that it didn't work as I expected, but the messages returned didn't help me.
Because it is difficult to debug applications deployed in the cloud like native Java applications, I plan to add some logs to Java code with SLF4J, and then check the logs generated by the Java application executing in the cloud to troubleshoot the problem.
SLF4J stands for Simple Logging Facade for Java, where Facade is actually a facade pattern in object-oriented design patterns. SLF4J is not a specific logging solution, it does not contain a specific implementation of logging itself, but only provides a look and feel for a variety of logging systems, which provides a lot of flexibility for specific applications, so that end users can choose the desired logging system when deploying their applications.
SLF4J is very easy to use, import the Logger and LoggerFactory of SLF4J into your application code:
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
Then use LoggerFactory in the reference code to get the logger instance:
static private Logger logger = LoggerFactory.getLogger(XCDService.class);
Then log with logger.info.
Upload the SLF4J logged code back to the cloud. I use SAP Cloud Platform.
Log into the SAP Cloud Platform console and click the Logging tab:
Point Configure Loggers:
Because my app code is under the com.sap.service package, I filter by the package name:
Set the Log Level for these two Loggers to INFO:
Use postman again to request the service deployed on SAP Cloud Platform, and then go to Cloud Platform Console to view the generated log file:
Click the View button to see the specific content of the log, and locate the cause of the problem at once. I set the value of the HTTP response header field Content-type on the server side to application/json, but the returned JSON string does not conform to the JSON format specification. After fixing this bug, the error will be solved.
About how to use SLF4J in the cloud environment for Java program logging to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.