agmoyano / node-jasper

JasperReports from Node.js
84 stars 52 forks source link

Problem when using Jasper version > 6.4.0 #36

Closed SVoyt closed 5 years ago

SVoyt commented 6 years ago

There is an error when using jasper 6.4.3 and above. Bug is in debug function code:

debug: ['loadJars', function(cb) { if(!options.debug) options.debug = 'off'; var levels = ['ALL', 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'OFF']; if(levels.indexOf((options.debug+'').toUpperCase()) == -1) options.debug = 'DEBUG'; var appender = java.newInstanceSync('org.apache.log4j.ConsoleAppender'); var pattern = java.newInstanceSync('org.apache.log4j.PatternLayout', "%d [%p|%c|%C{1}] %m%n"); appender.setLayout(pattern); appender.setThreshold(java.getStaticFieldValue("org.apache.log4j.Level", (options.debug+'').toUpperCase())); appender.activateOptions(); var root = java.callStaticMethodSync("org.apache.log4j.Logger", "getRootLogger"); root.addAppender(appender); cb(); }],

var appender = java.newInstanceSync('org.apache.log4j.ConsoleAppender'); ^

Error: Could not create class org.apache.log4j.ConsoleAppender java.lang.NoClassDefFoundError: org/apache/log4j/ConsoleAppender

agmoyano commented 6 years ago

Hello Sergey, it seems you don't have log4j's jar in your jasperreports lib directory.

Please check it out, and if not present, add it.

jasperreports-6.1.0-project.tar.gz comes with log4j-1.2.15.jar and was working.

Hope it helps.

SVoyt commented 6 years ago

Hi agmoyano, thanks for the quick response. The problem is that jasper > 6.4.0 using log4j 2.8.2 version, there is a different structure of libs, instead of one lib (log4j-1.2.15.jar) there are log4j-api lib, log4j-core lib etc.

agmoyano commented 6 years ago

Yes, you are right.. it seems org.apache.log4j.ConsoleAppender now it's called org.apache.logging.log4j.core.appender.ConsoleAppender. It seems log4j's configuration should be done through a ConfigurationBuilder as described in:

https://logging.apache.org/log4j/2.x/manual/customconfig.html

I've found some examples here on how to use it:

https://www.programcreek.com/java-api-examples/index.php?api=org.apache.logging.log4j.core.appender.ConsoleAppender

If you are willing to make a PR I'll check it out, and merge it if it's ok

Thanks

SVoyt commented 6 years ago

Thanks, i'll try