coldbox-modules / cborm

The ColdBox ORM enhancements for ColdFusion ORM & Hibernate. Make ORM not suck!
https://coldbox-orm.ortusbooks.com/
8 stars 17 forks source link

CBORM errors on newer Lucee versions because log4j appenders have moved #56

Open michaelborn opened 2 years ago

michaelborn commented 2 years ago

CBORM causes an error on Lucee 5.3.9.141 because lucee.commons.io.log.log4j.layout.ClassicLayout no longer exists.

Error finding log4j.layout.ClassicLayout on newer Lucee versions

See https://github.com/coldbox-modules/cborm/blob/development/models/util/ORMUtilSupport.cfc#L32-L39:

/**
 * Redirect all Hibernate logs to system.out
 */
if ( listFindNoCase( "Lucee", server.coldfusion.productname ) ) {
    var printWriter     = getPageContext().getConfig().getOutWriter();
    var layout          = createObject( "java", "lucee.commons.io.log.log4j.layout.ClassicLayout" );
    var consoleAppender = createObject( "java", "lucee.commons.io.log.log4j.appender.ConsoleAppender" ).init(
        printWriter,
        layout
    );
    hibernateLog.addAppender( consoleAppender );
    writeDump( var = "** Lucee Hibernate Logging Redirected", output = "console" );
}

It appears this moved to lucee.commons.io.log.log4j2.layout.ClassicLayout.

Ditto for lucee.commons.io.log.log4j.appender.ConsoleAppender, which moved to lucee.commons.io.log.log4j2.appender.ConsoleAppender

michaelborn commented 2 years ago

What's funny is that this shows in the test suite index.cfm page, but not in the test suite itself:

https://github.com/coldbox-modules/cborm/runs/7094574945?check_suite_focus=true#step:10:219

<td class="label">Java Stacktrace</td>
<td>lucee.runtime.exp.NativeException: cannot load class through its string name, because no definition for the class with the specified name [org.apache.log4j.Logger] could be found caused by (java.lang.ClassNotFoundException:org.apache.log4j.Logger not found by lucee.core [49];java.lang.ClassNotFoundException:org.apache.log4j.Logger;)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.commons.lang.ClassUtil.loadClass(ClassUtil.java:296)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.JavaProxy.loadClassByPath(JavaProxy.java:130)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.JavaProxy.loadClass(JavaProxy.java:65)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.JavaProxy.call(JavaProxy.java:60)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.CreateObject.doJava(CreateObject.java:140)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.CreateObject.call(CreateObject.java:62)<br><span style='margin-right: 1em;'>&nbsp;</span>
at lucee.runtime.functions.other.CreateObject.call(CreateObject.java:49)<br><span style='margin-right: 1em;'>&nbsp;</span>
at models.util.ormutilsupport_cfc$cf.udfCall1(/cborm/models/util/ORMUtilSupport.cfc:24)<br><span style='margin-right: 1em;'>&nbsp;</span>
at models.util.ormutilsupport_cfc$cf.udfCall(/cborm/models/util/ORMUtilSupport.cfc)
michaelborn commented 2 years ago

I've attempted to fix this via the following try...catch, but I can't verify that it is working.

Help, anyone?

try {
  // older Log4j code here...
} catch( any e ){
    // Log4j 2 implementation šŸ˜”
    var log4jLevel   = createObject( "java", "org.apache.logging.log4j.Level" );
    var logManager = createObject( "java", "org.apache.logging.log4j.LogManager" );
    var hibernateLog = logManager.getLogger( "org.hibernate" );
    var logEngine = getPageContext().getConfig().getLogEngine();
    var consoleAppender = logEngine.getAppender( getPageContext().getConfig(), logEngine.getClassicLayout(), "console", logEngine.appenderClassDefintion( "console" ), javaCast( "null", 0 ) );

    hibernateLog.setLevel( log4jLevel[ arguments.level ] );
    hibernateLog.addAppender( consoleAppender );
}