未能生成.log文件,但控制台输出是存在的

huangapple go评论81阅读模式
英文:

Failed to generate .log file, but output console is there

问题

我已经在Serenity Cucumber框架中尝试实现日志记录,并且它在控制台中打印日志,但是没有生成.log文件

这是位于src/test/resources目录下的logback-test.xml文件:

<configuration>
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<File name="File" fileName="admin.log">
			<encoder>
				<pattern> %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg ..................%n </pattern>
			</encoder>
		</File>
	</appender>
	<appender name="FILE" class="ch.qos.logback.core.FileAppender">
		<file>admin.log</file>
		<encoder>
			<pattern>
				%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg
				..................%n
			</pattern>
		</encoder>
	</appender>
	<logger name="root" level="DEBUG" />
	<logger name="net.serenitybdd" level="INFO" />
	<logger name="net.thucydides" level="INFO" />
	<root level="INFO">
		<appender-ref ref="STDOUT" />
	</root>
</configuration>

我在pom.xml中添加了以下依赖项:

<dependency>
	<groupId>ch.qos.logback</groupId>
	<artifactId>logback-classic</artifactId>
	<version>1.0.13</version>
</dependency>
英文:

I have tried to implement logs in the Serenity Cucumber framework and it prints logs in the console but doesn't generate a .log file.

This is logback-test.xml under src/test/resources

&lt;configuration&gt;
	&lt;appender name=&quot;STDOUT&quot;
		class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;
		&lt;File name=&quot;File&quot; fileName=&quot;admin.log&quot;&gt;
			&lt;encoder&gt;
				&lt;pattern&gt; %d{HH:mm:ss.SSS}
					[%thread] %-5level %logger{36} - %msg ..................%n &lt;/pattern&gt;
			&lt;/encoder&gt;
		&lt;/File&gt;
	&lt;/appender&gt;
	&lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.FileAppender&quot;&gt;
		&lt;file&gt;admin.log&lt;/file&gt;
		&lt;encoder&gt;
			&lt;pattern&gt;
				%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg
				..................%n
			&lt;/pattern&gt;
		&lt;/encoder&gt;
	&lt;/appender&gt;
	&lt;logger name=&quot;root&quot; level=&quot;DEBUG&quot; /&gt;
	&lt;logger name=&quot;net.serenitybdd&quot; level=&quot;INFO&quot; /&gt;
	&lt;logger name=&quot;net.thucydides&quot; level=&quot;INFO&quot; /&gt;
	&lt;root level=&quot;INFO&quot;&gt;
		&lt;appender-ref ref=&quot;STDOUT&quot; /&gt;
	&lt;/root&gt;
&lt;/configuration&gt;


Added below dependency in pom.xml

&lt;dependency&gt;
			&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
			&lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
			&lt;version&gt;1.0.13&lt;/version&gt;
		&lt;/dependency&gt;

答案1

得分: 1

&lt;configuration&gt;
    &lt;appender name=&quot;STDOUT&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            &lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
    &lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.FileAppender&quot;&gt;
        &lt;file&gt;admin.log&lt;/file&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            &lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
    &lt;logger name=&quot;root&quot; level=&quot;DEBUG&quot; /&gt;
    &lt;logger name=&quot;net.serenitybdd&quot; level=&quot;INFO&quot; /&gt;
    &lt;logger name=&quot;net.thucydides&quot; level=&quot;INFO&quot; /&gt;
    &lt;root level=&quot;INFO&quot;&gt;
        &lt;appender-ref ref=&quot;STDOUT&quot; /&gt;
        &lt;appender-ref ref=&quot;FILE&quot; /&gt;
    &lt;/root&gt;
&lt;/configuration&gt;
英文:

A ConsoleAppender won't write to a file, and will just ignore the file configuration element under it. Instead, you should use a FileAppender:

&lt;configuration&gt;
    &lt;appender name=&quot;STDOUT&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            &lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
    &lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.FileAppender&quot;&gt;
        &lt;file&gt;admin.log&lt;/file&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            &lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
    &lt;logger name=&quot;root&quot; level=&quot;DEBUG&quot; /&gt;
    &lt;logger name=&quot;net.serenitybdd&quot; level=&quot;INFO&quot; /&gt;
    &lt;logger name=&quot;net.thucydides&quot; level=&quot;INFO&quot; /&gt;
    &lt;root level=&quot;INFO&quot;&gt;
        &lt;appender-ref ref=&quot;STDOUT&quot; /&gt;
        &lt;appender-ref ref=&quot;FILE&quot; /&gt;
    &lt;/root&gt;
&lt;/configuration&gt;

huangapple
  • 本文由 发表于 2020年9月24日 20:14:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64046227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定