[logback-dev] [JIRA] Updates for LOGBACK-1589: Could not find my custom class when used in scala play framework

QOS.CH (JIRA) noreply-jira at qos.ch
Thu Nov 18 12:53:00 CET 2021


logback / LOGBACK-1589 [Open]
Could not find my custom class when used in scala play framework

==============================

Here's what changed in this issue in the last few minutes.
This issue has been created
This issue is now assigned to you.

View or comment on issue using this link
https://jira.qos.ch/browse/LOGBACK-1589

==============================
 Issue created
------------------------------

Devendra Vishwakarma created this issue on 18/Nov/21 12:40 PM
Summary:              Could not find my custom class when used in scala play framework
Issue Type:           Bug
Assignee:             Logback dev list
Components:           logback-classic
Created:              18/Nov/21 12:40 PM
Environment:
  Scala version - 2.13.4
  Scala play - 2.8.8
  Java - Openjdk 1.8
  Environment - local development
Labels:               configuration logging
Priority:             Critical
Reporter:             Devendra Vishwakarma
Description:
  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 - 
  {code:java}
  11:32:39,796 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler at 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 at 4fa3c3b - [msgNoPW] is not a valid conversion word
  {code}
  
  And this is my logback.xml -
  Note that I am using my own class called utils.LoggingPasswordMask in converionRule
  {code:java}
  <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>
  
  {code}


==============================
 This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59)



More information about the logback-dev mailing list