azure - 来自 Azure 的 Tomcat Web App 中的位置标准输出日志

标签 azure tomcat azure-web-app-service

我正在使用 Azure Web 应用程序,并尝试调试我在 Tomcat 容器内的 Java 应用程序。

当我使用 Visual Studio 或 FTP 或 Kudo 转到“日志文件”文件夹时,我只看到以下内容

  1. 本地主机
  2. 卡特琳娜
  3. 房东经理

enter image description here

我没有看到标准输出。我的应用程序中的许多行都使用 System.out.println()(在此阶段我不打算将它们全部替换为 Logger)

如何查看标准输出? 我尝试在 App Service Logs 中添加尽可能多的日志,但这没有帮助。

enter image description here

最佳答案

我在 Azure 门户上使用 Java 和 Tomcat 配置了我的 WebApp,如下图所示。

enter image description here

所以在Kudu控制台路径D:\Program Files (x86)\apache-tomcat-9.0.14\下可以找到Tomcat 9.0.14的logging.properties文件conf如下图。

enter image description here

可以看到使用了Tomcat的默认日志记录,所以System.out.println的这些控制台输出不会写入到D:\home\LogFiles\的这些日志文件中应用.

不过,我尝试在D:\home\site\wwwroot\webapps\ROOT\index.jsp中写了一些代码如下。

<%@ page import="java.util.logging.*" %>

<%
    Logger logger = Logger.getLogger("Hello");
    out.println("Hello, world from webapps/ROOT/index.jsp on Tomcat on cloud.<br>");
    System.out.println("System.out >> Hello, world from webapps/ROOT/index.jsp on Tomcat on cloud.");
    logger.warning("Logger Level Warning >> Hello, world from webapps/ROOT/index.jsp on Tomcat on cloud. ");
    logger.info("Logger Level Info >> Hello, world from webapps/ROOT/index.jsp on Tomcat on cloud. ");
    logger.fine("Logger Level Fine >> Hello, world from webapps/ROOT/index.jsp on Tomcat on cloud. ");
%>

然后,我可以看到只有日志记录级别warninginfo的日志被写入D:\home\LogFiles\Application\catalina.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx。 2019-08-19.log,如下图,因为日志级别优先级为SEVERE > WARNING > INFO > CONFIG > FINE > FINER > FINEST

enter image description here

由于 File System Restrictions/Considerations Azure WebApp,除D:\home外,其他路径不能写。

所以如果你想将一些日志写入文件,请使用 java.util.logging.Logger 而不是 System.out,或者使用其他日志框架像 log4jslf4j

希望对您有所帮助。

关于azure - 来自 Azure 的 Tomcat Web App 中的位置标准输出日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545794/

相关文章:

python - 尝试连接到 CosmosDB 数据库时出现 pymongo.errors.ServerSelectionTimeoutError

Tomcat中的URL路径含义

java - Grails 应用程序中的 Perm Gem 问题

azure - 通过 AzureCLI 启用对 Azure 应用服务的公共(public)访问

visual-studio - 快照调试: Failed to get response from URL

c# - 如何为 Azure AD 创建和使用刷新 token

azure - AKS LoadBalancer 仅将流量发送到一个 Pod

java - 在 Java Web 应用程序中加载外部库

laravel - "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"Azure 上的 Laravel

java - 无法连接 Microsoft Azure Vm 中的端口