在apache flink中使用slf4j记录器时出错

bzzcjhmw  于 2021-06-25  发布在  Flink
关注(0)|答案(1)|浏览(577)

我想在flink中输出日志,我已经创建了下面提到的记录器代码
我已经进口了那家伐木厂

import org.slf4j.LoggerFactory;

类包含如下代码

final  static org.slf4j.Logger logger = LoggerFactory.getLogger(CEPMonitoring.class);

     public static void main(String[] args) throws Exception {

     logger.info("execution began \n "); 
      }

但是,这不是打印任何内容。而且,我没有 logback.xml 文件如中所述https://ci.apache.org/projects/flink/flink-docs-release-0.7/internal_logging.html
p、 当我使用

final  static Logger logger = LoggerFactory.getLogger(CEPMonitoring.class);

最终让我开始写作

final static org.slf4j.Logger logger = LoggerFactory.getLogger(CEPMonitoring.class);

它给了一个错误,然后我不得不
最重要的是,我在运行程序时收到以下警告

log4j:WARN No appenders could be found for logger (org.stsffap.cep.monitoring.CEPMonitoring).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我不知道该怎么办?

fhity93d

fhity93d1#

我可以通过创建一个 log4j.properties 文件在 src/main/resources 文件夹并向其中添加以下代码

log4j.rootLogger=INFO, console

# patterns:

# d = date

# c = class

# F = file

# p = priority (INFO, WARN, etc)

# x = NDC (nested diagnostic context) associated with the thread that generated the logging event

# m = message

# Log all infos in the console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss.SSS} %5p [%-10c] %m%n

# Log all infos in flink-app.log

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.file=flink-app.log
log4j.appender.file.append=false
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss.SSS} %5p [%-10c] %m%n

# suppress info messages from flink

log4j.logger.org.apache.flink=WARN

为了了解这些属性的含义,我将推荐观看https://www.youtube.com/watch?v=-gkrufu_sugc
也为了抑制以下警告
log4j:warn请正确初始化log4j系统。
添加以下行

PropertyConfigurator.configure(" path to log4j.properties");

相关问题