Log4j未记录到控制台

webghufk  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(303)

我试图从命令行运行一个类文件,它是用log4j2编译的,但它没有在控制台上打印任何东西。你知道是什么问题吗?

java -Dlog4j2.debug=true -DDlog4j.configurationFile=file:log4j2.Properties demo.selenium.IBanTest

我希望控制台上显示logger.debug消息。

public static void IBanUpdateTest(){
        driver.get("http://google.com/demo-web-1.0-SNAPSHOT"); //define the url
        String pageTitle = driver.getTitle();       //get the title of the webpage
        Assert.assertEquals("iBAN Register Form", pageTitle);    //verify the title of the webpage
        logger.debug("The title of this page is: {}", pageTitle);
        driver.findElement(By.id("0iban")).clear();//clear the input field before entering any value
        driver.findElement(By.id("0iban")).sendKeys("5464564654");//enter the IBan Value
        driver.findElement(By.id("0businessIdentifierCode")).clear();
        driver.findElement(By.id("0businessIdentifierCode")).sendKeys("54645646548546465"); //enter the BIC value
        driver.findElement(By.id("0updateRow")).click();      //click Update button
        logger.debug("Updated the row successfully");
}

-Dlog4j2.debug=true output:

DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
DEBUG StatusLogger Unable to access Context Data Providers org.apache.logging.log4j.core.util.ContextDataProvider: Provider com.newrelic.logging.log4j2.NewRelicContextDataProvider could not be instantiated
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger Took 1.065501 seconds to load 217 plugins from sun.misc.Launcher$AppClassLoader@75b84c92
DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger Starting LoggerContext[name=75b84c92, org.apache.logging.log4j.core.LoggerContext@627551fb]...
DEBUG StatusLogger Reconfiguration started for context[name=75b84c92] at URI null (org.apache.logging.log4j.core.LoggerContext@627551fb) with optional ClassLoader: null
DEBUG StatusLogger Initializing Thread Context Data Service Providers
DEBUG StatusLogger Thread Context Data Service Provider initialization complete
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger Missing dependencies for Yaml support, ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory is inactive
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger Missing dependencies for Json support, ConfigurationFactory org.apache.logging.log4j.core.config.json.JsonConfigurationFactory is inactive
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@3b084709
TRACE StatusLogger Trying to find [log4j2-test75b84c92.properties] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yaml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test75b84c92.json] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test75b84c92.jsn] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test75b84c92.xml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test75b84c92.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.properties] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.yml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.yaml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.json] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.jsn] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.xml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2-test.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2-test.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.properties] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.yml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.yaml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.json] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.jsn] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j275b84c92.xml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j275b84c92.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j275b84c92.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.properties] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.properties] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.yml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.yml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.yaml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.yaml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.json] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.json] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.jsn] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.jsn] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.xml] using context class loader sun.misc.Launcher$AppClassLoader@75b84c92.
TRACE StatusLogger Trying to find [log4j2.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.xml] using sun.misc.Launcher$AppClassLoader@75b84c92 class loader.
TRACE StatusLogger Trying to find [log4j2.xml] using ClassLoader.getSystemResource().
WARN StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
INFO StatusLogger Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-2
DEBUG StatusLogger Apache Log4j Core 2.14.1 initializing configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3224f60b
DEBUG StatusLogger Installed 1 script engine
DEBUG StatusLogger Oracle Nashorn version: 1.8.0_292, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
DEBUG StatusLogger PluginManager 'Core' found 123 plugins
DEBUG StatusLogger PluginManager 'Level' found 0 plugins
DEBUG StatusLogger Configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3224f60b initialized
DEBUG StatusLogger Starting configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3224f60b
DEBUG StatusLogger Started configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3224f60b OK.
TRACE StatusLogger Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@8807e25...
TRACE StatusLogger DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
TRACE StatusLogger DefaultConfiguration stopping root LoggerConfig.
TRACE StatusLogger DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
TRACE StatusLogger DefaultConfiguration stopping remaining Appenders.
DEBUG StatusLogger Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger OutputStream closed
DEBUG StatusLogger Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
DEBUG StatusLogger Appender DefaultConsole-1 stopped with status true
TRACE StatusLogger DefaultConfiguration stopped 1 remaining Appenders.
TRACE StatusLogger DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
DEBUG StatusLogger Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@8807e25 OK
TRACE StatusLogger Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@79e2c065
TRACE StatusLogger Reregistering context (1/1): '75b84c92' org.apache.logging.log4j.core.LoggerContext@627551fb
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=StatusLogger'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=ContextSelector'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=Loggers,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=Appenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=AsyncAppenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=AsyncLoggerRingBuffer'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=75b84c92,component=Loggers,name=*,subtype=RingBuffer'
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=75b84c92
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=75b84c92,component=StatusLogger
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=75b84c92,component=ContextSelector
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=75b84c92,component=Appenders,name=DefaultConsole-2
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock does not support precise timestamps.
TRACE StatusLogger Using DummyNanoClock for nanosecond timestamps.
DEBUG StatusLogger Reconfiguration complete for context[name=75b84c92] at URI NULL_SOURCE (org.apache.logging.log4j.core.LoggerContext@627551fb) with optional ClassLoader: null
DEBUG StatusLogger Shutdown hook enabled. Registering a new one.
DEBUG StatusLogger LoggerContext[name=75b84c92, org.apache.logging.log4j.core.LoggerContext@627551fb]

启动正常。

a64a0gku

a64a0gku1#

找到了。在查看调试跟踪后,它正在寻找log4j2-test.properties而不是log4j2.properties。所以我将文件重命名为log4j2-test.properties,它开始工作。
设置环境变量:

CLASSPATH = ".:/home/user/:selenium-chrome-driver-3.12.0.jar:selenium-server-standalone-3.13.0.jar:guava-13.0.1.jar:junit4.jar:log4j-core-2.14.1.jar:log4j2-2.3.jar:log4j-api-2.14.1.jar"

将文件重命名为log4j2-test.properties,并以以下身份运行java程序:

sh 'java -Dlog4j.configurationFile=file:log4j2-test.properties demo.selenium.IBanTest '

相关问题