Я пытался сгенерировать файл журнала в Intellij, используя Log4j2. Я создал файл свойств для Log4j2 и настроил его в базовом классе моей платформы. Мои журналы создаются в моем каталоге проекта root без каких-либо проблем. Но когда я открываю файл журнала, Intellij показывает мне ошибку для формата журнала, поэтому может ли кто-нибудь помочь мне решить эту проблему с Intellij.
Вот мой файл log4j2.properties: -
//name=PropertiesConfig
property.filename = logs
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/propertieslogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.append=true
loggers=file
logger.file.name=com.framework
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
Вот мои журналы консоли: -
Testing started at 4:09 PM ...
/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin/java -Dorg.jetbrains.run.directory=/Users/keshavmac/IdeaProjects/com.CucumberHybrid/src/test/java/com/framework/features -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=58681:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/lib/tools.jar:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/test-classes:/Users/keshavmac/IdeaProjects/com.CucumberHybrid/target/classes:/Users/keshavmac/.m2/repository/org/apache/logging/log4j/log4j-core/2.13.3/log4j-core-2.13.3.jar:/Users/keshavmac/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.3/log4j-api-2.13.3.jar:/Users/keshavmac/.m2/repository/io/github/bonigarcia/webdrivermanager/3.8.1/webdrivermanager-3.8.1.jar:/Users/keshavmac/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/keshavmac/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar:/Users/keshavmac/.m2/repository/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar:/Users/keshavmac/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar:/Users/keshavmac/.m2/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar:/Users/keshavmac/.m2/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10.jar:/Users/keshavmac/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/keshavmac/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/Users/keshavmac/.m2/repository/org/rauschig/jarchivelib/1.0.0/jarchivelib-1.0.0.jar:/Users/keshavmac/.m2/repository/org/apache/commons/commons-compress/1.18/commons-compress-1.18.jar:/Users/keshavmac/.m2/repository/org/jsoup/jsoup/1.11.3/jsoup-1.11.3.jar:/Users/keshavmac/.m2/repository/org/testng/testng/6.14.3/testng-6.14.3.jar:/Users/keshavmac/.m2/repository/com/beust/jcommander/1.72/jcommander-1.72.jar:/Users/keshavmac/.m2/repository/org/apache-extras/beanshell/bsh/2.0b6/bsh-2.0b6.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-java/6.1.2/cucumber-java-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-core/6.1.2/cucumber-core-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-gherkin/6.1.2/cucumber-gherkin-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-gherkin-messages/6.1.2/cucumber-gherkin-messages-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/messages/12.1.1/messages-12.1.1.jar:/Users/keshavmac/.m2/repository/io/cucumber/tag-expressions/3.0.0/tag-expressions-3.0.0.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-expressions/10.2.1/cucumber-expressions-10.2.1.jar:/Users/keshavmac/.m2/repository/io/cucumber/datatable/3.3.1/datatable-3.3.1.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-plugin/6.1.2/cucumber-plugin-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/docstring/6.1.2/docstring-6.1.2.jar:/Users/keshavmac/.m2/repository/io/cucumber/html-formatter/6.0.3/html-formatter-6.0.3.jar:/Users/keshavmac/.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar:/Users/keshavmac/.m2/repository/net/masterthought/cucumber-reporting/5.3.0/cucumber-reporting-5.3.0.jar:/Users/keshavmac/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.10.1/jackson-databind-2.10.1.jar:/Users/keshavmac/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.10.1/jackson-annotations-2.10.1.jar:/Users/keshavmac/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.10.1/jackson-core-2.10.1.jar:/Users/keshavmac/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.10.1/jackson-datatype-jsr310-2.10.1.jar:/Users/keshavmac/.m2/repository/org/apache/velocity/velocity-engine-core/2.1/velocity-engine-core-2.1.jar:/Users/keshavmac/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/Users/keshavmac/.m2/repository/joda-time/joda-time/2.10.5/joda-time-2.10.5.jar:/Users/keshavmac/.m2/repository/org/codehaus/plexus/plexus-utils/3.3.0/plexus-utils-3.3.0.jar:/Users/keshavmac/.m2/repository/com/googlecode/owasp-java-html-sanitizer/owasp-java-html-sanitizer/20191001.1/owasp-java-html-sanitizer-20191001.1.jar:/Users/keshavmac/.m2/repository/commons-configuration/commons-configuration/1.10/commons-configuration-1.10.jar:/Users/keshavmac/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar:/Users/keshavmac/.m2/repository/io/cucumber/cucumber-testng/6.1.2/cucumber-testng-6.1.2.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-api/3.141.59/selenium-api-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/3.141.59/selenium-chrome-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/3.141.59/selenium-edge-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/3.141.59/selenium-firefox-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/3.141.59/selenium-ie-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-opera-driver/3.141.59/selenium-opera-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/3.141.59/selenium-remote-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/3.141.59/selenium-safari-driver-3.141.59.jar:/Users/keshavmac/.m2/repository/org/seleniumhq/selenium/selenium-support/3.141.59/selenium-support-3.141.59.jar:/Users/keshavmac/.m2/repository/net/bytebuddy/byte-buddy/1.8.15/byte-buddy-1.8.15.jar:/Users/keshavmac/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/Users/keshavmac/.m2/repository/com/google/guava/guava/25.0-jre/guava-25.0-jre.jar:/Users/keshavmac/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/Users/keshavmac/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar:/Users/keshavmac/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar:/Users/keshavmac/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar:/Users/keshavmac/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar:/Users/keshavmac/.m2/repository/com/squareup/okhttp3/okhttp/3.11.0/okhttp-3.11.0.jar:/Users/keshavmac/.m2/repository/com/squareup/okio/okio/1.14.0/okio-1.14.0.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/keshavmac/Library/Application Support/JetBrains/IdeaIC2020.2/plugins/cucumber-java/lib/cucumber-jvmFormatter.jar:/Users/keshavmac/Library/Application Support/JetBrains/IdeaIC2020.2/plugins/cucumber-java/lib/cucumber-jvmFormatter5.jar:/Users/keshavmac/Library/Application Support/JetBrains/IdeaIC2020.2/plugins/cucumber-java/lib/cucumber-jvmFormatter4.jar:/Users/keshavmac/Library/Application Support/JetBrains/IdeaIC2020.2/plugins/cucumber-java/lib/cucumber-jvmFormatter3.jar io.cucumber.core.cli.Main --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter --name ^To test search functionality with blank submit$ --glue com.framework.utils --glue com.framework.stepDef /Users/keshavmac/IdeaProjects/com.CucumberHybrid/src/test/java/com/framework/features/Home.feature
Invoking new Webdriver instance
[INFO ] 2020-08-07 16:09:32.230 [main] BaseSetup - New Webdriver instance invoked
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 27490
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Aug 07, 2020 4:09:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
The page title verified is My Store
The validation for mainbanner on homepage has been completed
The validation for search field on homepage has been completed
Closing existing Webdriver instance
[INFO ] 2020-08-07 16:09:41.853 [main] BaseSetup - Webdriver instance closed
1 Scenarios (1 passed)
5 Steps (5 passed)
0m10.408s
Process finished with exit code 0
Вот мой файл базового класса, в котором я использую диспетчер журналов и вызываю журналы: -
package com.framework.utils;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.safari.SafariDriver;
import java.util.concurrent.TimeUnit;
public class BaseSetup {
protected static WebDriver driver=null;
protected static PropertiesReader read;
protected static Logger logger;
@Before
public void pre_setup(){
read=new PropertiesReader();
logger= LogManager.getLogger(BaseSetup.class.getName());
}
public static WebDriver webdriverSetup(){
if (driver==null){
System.out.println("Invoking new Webdriver instance");
logger.info("New Webdriver instance invoked");
if(read.getBrowsername().equalsIgnoreCase("chrome")){
WebDriverManager.chromedriver().setup();
ChromeOptions options=new ChromeOptions();
options.addArguments("--disable-notifications");
driver=new ChromeDriver(options);
}
else if (read.getBrowsername().equalsIgnoreCase("safari")) {
driver=new SafariDriver();
}
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
return driver;
}
@After
public void teardown(){
if (driver!=null){
System.out.println("Closing existing Webdriver instance");
logger.info("Webdriver instance closed");
driver.close();
driver.quit();
driver=null;
}
}
}
Вот ошибка, с которой я столкнулся в Intellij в файле журнала для формата журнала: -
введите описание изображения здесь