Details
-
Bug
-
Resolution: Won't Fix
-
Critical
-
None
-
None
-
Scala version - 2.13.4
Scala play - 2.8.8
Java - Openjdk 1.8
Environment - local development
Description
[Sorry I have to open a bug here, because I am feeling helpless with this issue]
This is getting very frustrating to me to make logback work if I use my own custom class anywhere with in conversionRule or in appender. Because logback never finds those classes when running my scala play app in local mode by either running via IntelliJ or sbt run.
I have read all over internet, they all blame logback because it internally uses some different classloader and does not find any other classes if they are not packaged in jar file.
Error I get -
11:32:39,796 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@4fa3c3b - Failed to instantiate converter class [utils.LoggingPasswordMask] for keyword [msgNoPW] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type utils.LoggingPasswordMask at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type utils.LoggingPasswordMask Caused by: java.lang.ClassNotFoundException: utils.LoggingPasswordMask at at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56) at ... 51 common frames omitted 11:32:39,796 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@4fa3c3b - [msgNoPW] is not a valid conversion word
And this is my logback.xml -
Note that I am using my own class called utils.LoggingPasswordMask in converionRule
<configuration> <property name="LOG_PATH" value="${LOG_PATH:-logs}"/> <property name="MODULE_NAME" value="nhp"/> <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel"/> <conversionRule conversionWord="msgNoPW" converterClass="utils.LoggingPasswordMask" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>[%date] %highlight([%level]) [%logger %file:%line] %msgNoPW%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Append>true</Append> <File>${LOG_PATH}/${MODULE_NAME}_play.log</File> <encoder> <pattern>%date %-5level - %logger - %msgNoPW%n%xException</pattern> <charset>utf8</charset> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_PATH}/${MODULE_NAME}_play-%d{yyyy-MM-dd}.log.gz</fileNamePattern> <maxHistory>30</maxHistory> <totalSizeCap>1GB</totalSizeCap> </rollingPolicy> </appender> <appender name="FILE_USE_CASE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Append>true</Append> <File>${LOG_PATH}/${MODULE_NAME}_use_case.log</File> <encoder> <pattern>%date %-5level - %msgNoPW%n%xException</pattern> <charset>utf8</charset> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_PATH}/${MODULE_NAME}_use_case-%d{yyyy-MM-dd}.log.gz</fileNamePattern> <maxHistory>30</maxHistory> <totalSizeCap>1GB</totalSizeCap> </rollingPolicy> </appender> <root level="INFO"> <appender-ref ref="FILE"/> </root> <logger name="BatchUseCaseProcessLogger" level="INFO" additivity="false"> <appender-ref ref="FILE_USE_CASE"/> </logger> <logger name="play" level="INFO" /> <logger name="application" level="DEBUG" /> <logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG" /> <logger name="akka.persistence" level="DEBUG" /> <logger name="org.quartz" level="DEBUG" /> <root level="INFO"> <appender-ref ref="STDOUT" /> </root> </configuration>