我试图根据以下XML文件中定义的属性生成动态日志文件,该文件的名称为“ logback.xml ”。
<Configuration status="DEBUG">
<Properties>
<Property name="log-path">/Users/amitraj/Downloads/KotlinLogging</Property>
</Properties>
<Appenders>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<RollingFile name="RollingFile" fileName="${log-path}/app.log"
filePattern="${log-path}/app-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<pattern>%d{dd/MM/yyyy HH:mm:ss} [%-5p/%t]: %C{1}(%L): %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB"/>
<OnStartupTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="root" level="debug" additivity="false">
<appender-ref ref="RollingFile" level="debug"/>
<appender-ref ref="console" level="debug"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
但是我面临以下问题: 1.当我尝试通过以下行导入log4js时。我在Apache上遇到错误:
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
我的记录器代码如下:
object MyApp {
// Define a static logger variable so that it references the
// Logger instance named "MyApp".
private val logger: Logger = LogManager.getLogger(MyApp::class.java)
@JvmStatic
fun main(args: Array<String>) {
logger.trace("Entering application.")
logger.trace("Exiting application.")
}
}