My log4j statements are showing ?s for line numbers.
What I've tried
Other answers around the web say this happens when you haven't compiled debug information into your classes. In Ant for example, this would be done with <javac debug="true" .... Searching for a way to do this in gradle yields only
http://gradle.org/docs/2.3-rc-2/dsl/org.gradle.api.tasks.compile.CompileOptions.html
debug - Tells whether to include debugging information in the generated class files. Defaults to true
I verified this by putting println compileGroovy.options.debug in my build.gradle and it prints true. I also found http://forums.gradle.org/gradle/topics/compile-groovy-with-debugging-information, which recommended using tasks.withType(GroovyCompile) { options.debug = true }, which also did not work. Finally, I found compileGroovy.options.debugOptions.debugLevel, which can have source, lines, or vars. This is null by default, but setting it to source,lines did not give my line information.
Reproducing
gradle init --type groovy-library
Edit src/main/groovy/Library.groovy to have the additional lines:
import groovy.util.logging.Log4j
#Log4j
class Library {
boolean someLibraryMethod() {
log.info "XXXXXXXXXXXXX"
true
}
}
Add
compile 'log4j:log4j:1.2.17' to build.gradle
Add the file src/main/resources/log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %c:%L - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
And finally run gradle clean test -i and observe that you see
2015-03-30 08:47:31,996 Library:? - XXXXXXXXXXXXX
Note the ? in the message.
Version information
$ gradle -version
------------------------------------------------------------
Gradle 2.3
------------------------------------------------------------
Build time: 2015-02-16 05:09:33 UTC
Build number: none
Revision: 586be72bf6e3df1ee7676d1f2a3afd9157341274
Groovy: 2.3.9
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS: Windows 7 6.1 amd64
$ groovy -version
Groovy Version: 2.4.3 JVM: 1.8.0_40 Vendor: Oracle Corporation OS: Windows 7
$ java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
My question is, of course, how do I get line numbers to show instead of question marks?
Groovy includes the line numbers in the class files. The problem is that groovy calls methods slightly differently than Java which confuses the Log4j code that determines the line number.
In particular, if you change the line
log.info "XXXXXXXXXXXXX"
to
log.error "XXXXXXXXXXXXX", new Exception('test')
you can see some reflection methods are called when groovy invokes methods. The topmost method in the stack trace I generated was sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method), which, being a native method, doesn't have a line number. This is what Log4j is looking at. Unfortunately, there's no easy was to filter the stacktrace Log4j uses or tell Log4j to look further down the stack.
One possible solution is to turn on static compilation. If you add #groovy.transform.CompileStatic to the Library class or method you'll get the correct line number.
Related
I am working on uplift project to uplift Apache 412 to latest Apache POI 5.2.2 version. Everything is working fine on local standalone program in Netbeans IDE 12.2. But when I move it to server WebLogic 14C that run on Java 8, its not working. Also it does not give any errors in the logs.
When I try to export to Excel in my Jdeveloper, I am getting the error "<incident 305 created with problem key "DFW-99998 [java.lang.NoSuchMethodError]" with Apache POI 522 JARS. The same java program is working fine in Apache POI 4.1.2 API.
I enabled verbose classloading in Jdeveloper but it does not give any POI specific errors.
-verbose:class -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:-DisplayVMOutput -XX:LogFile=C:\Record.log
I am using the below Apache POI JARS
commons-collections4-4.4.jar commons-compress-1.21.jar
commons-io-2.11.0.jar commons-math3-3.6.1.jar log4j-api-2.17.2.jar
log4j-core-2.17.2.jar poi-5.2.2.jar poi-ooxml-5.2.2.jar
poi-ooxml-full-5.2.2.jar SparseBitSet-1.2.jar xmlbeans-5.0.3.jar
In weblgic.xml I have below Configuration.
<prefer-application-packages>
<package-name>org.apache.commons.collections4.*</package-name>
<package-name>org.apache.commons.compress.*</package-name>
<package-name>org.apache.poi.*</package-name>
<package-name>org.apache.xmlbeans.*</package-name>
<package-name>org.openxmlformats.*</package-name>
<package-name>schemaorg_apache_xmlbeans.*</package-name>
<package-name>schemaorg_apache_xmlbeans.system.sXMLCONFIG.*</package-name>
<package-name>schemaorg_apache_xmlbeans.system.sXMLLANG.*</package-name>
<package-name>schemaorg_apache_xmlbeans.system.sXMLSCHEMA.*</package-name>
<package-name>schemaorg_apache_xmlbeans.system.sXMLTOOLS.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLCONFIG/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLLANG/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLSCHEMA/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLTOOLS/TypeSystemHolder.class</resource-name>
</prefer-application-resources>
Do i need any add any configuration in weblogic.xml file ? please let me know. how to get more stacktrace and error information when the API fails. When i debugged this issue,below line fails and i am getting NoSuchMethodError.
**workbook = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true); - this line fails.
workbook.setCompressTempFiles(true);**
I found this article helpful, but there is a new dependency on IOUtils.byteArray that the answer doesn't handle. It results in this specific error because the version of commons IO that comes with WL doesn't support this method.
java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.byteArray(I)[B
Here is my modified weblogic.xml to account for that. We are on WL 14 with Java 11.
<weblogic-web-app
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">
<context-root>xxx</context-root>
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>org.apache.commons.*</package-name>
<package-name>org.apache.poi.*</package-name>
<package-name>org.apache.xmlbeans.*</package-name>
<package-name>org.openxmlformats.*</package-name>
<package-name>schemaorg_apache_xmlbeans.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLCONFIG/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLLANG/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLSCHEMA/TypeSystemHolder.class</resource-name>
<resource-name>schemaorg_apache_xmlbeans/system/sXMLTOOLS/TypeSystemHolder.class</resource-name>
</prefer-application-resources>
</container-descriptor>
<description>xxx</description>
<weblogic-version>14.1.1</weblogic-version>
</weblogic-web-app>
Thanks, #kevin herein is my response to the above similar problem struggled for hrs to fix this.
Create your weblogic.xml file inside WEB-INF if not present and add the below code snippet
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>org.apache.commons.*</package-name>
<package-name>org.apache.poi.*</package-name>
<package-name>org.apache.xmlbeans.*</package-name>
<package-name>org.openxmlformats.*</package-name>
<package-name>schemaorg_apache_xmlbeans.*</package-name>
</prefer-application-packages>
</container-descriptor>
</weblogic-web-app>
I have a puppet server 5.3 which logs to logstash.
Daily I get ~90k messages, 95% of which are with log level INFO.
I would like to get only the WARN and ERROR level but regardless what I try, I still get the INFOs.
This is how I send the data to logstash via logback.xml:
<!-- This is the logstash part -->
<appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender">
<host>logserverhostname.com</host>
<port>514</port>
<level>WARN</level>
</appender>
<!-- End of the logstash part -->
<root level="WARN">
<appender-ref ref="stash" />
</root>
This is what I get when I check Kibana:
message:{"#timestamp":"2019-03-26T12:54:13.493+01:00","#version":1,"message":"Puppet 'replace_facts' command for somehost.com submitted to PuppetDB with UUID 92ba53a7-83f2-4438-b1da-f39cd7ccc844","logger_name":"puppetserver","thread_name":"qtp1518931796-63","level":"INFO","level_value":20000,"HOSTNAME":"puppet-server.com"} severity_label:Emergency severity:0 tags:syslog, _grokparsefailure_sysloginput #timestamp:March 26th 2019, 12:54:13.492 priority:0 #version:1 facility_label:kernel host:IP.IP.IP.IP facility:0 _id:v6PZuWkBButu0N-H0QkS _type:doc _index:syslog-2019.03.26 _score: -
I can filter out the result in Kibana, but I would prefer that I do not feed it with useless messages, thus saving IO, network traffic and disk space.
I tried to setup custom Log4J appenders in Tibco BW/Designer.
I added to <tibco_folder>/bw/5.11/lib/log4j.xml the following appender:
<appender name="TestFile" class="org.apache.log4j.FileAppender">
<param name="file" value="d:/temp/tibco-test.log"/>
<param name="Threshold" value="DEBUG"/>
<param name="append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy MMM dd HH:mm:ss:SSS 'GMT'} %X{offset} %X{engine} %X{role} [%X{msgCategory}] %X{msgcode} %m %n"/>
</layout>
</appender>
and then I added <appender-ref ref="TestFile"/> to each logger, including bw.logger, beside the tibco_bw_log appender. The messages are sent to tibco_bw_log, but not to my appender.
My appender is getting only some logs like the below, logs that don't appear in tibco_bw_log appender (c:\Users\<me>\.TIBCO\logs\<app_name>.log)
2017 Feb 21 17:05:16:693 GMT [] no system property set, defaulting to entrust61 since got class com.entrust.toolkit.security.provider.Initializer
2017 Feb 21 17:05:16:698 GMT [] getVendor()=entrust61
2017 Feb 21 17:05:16:719 GMT [] Initializing Entrust crypto provider in NON FIPS 140-2 mode; insert provider as normal
2017 Feb 21 17:05:17:302 GMT [] using X9_31usingDESede
2017 Feb 21 17:05:18:021 GMT [] getVendor()=entrust61
2017 Feb 21 17:05:18:023 GMT [] Initialized crypto vendor entrust61
java.lang.Exception: FOR TRACING ONLY -- NOT AN ERROR
at com.tibco.security.impl.new.F.init(CryptoVendor.java:69)
...
Even if I remove the tibco_bw_log appender from bw.logger, the logs are still going there and not to my logger. I changed my appender name to tibco_bw_log and removed the original appender, but then I was getting the error: "org.apache.log4j.FileAppender cannot be cast to com.tibco.share.util.BWLogFileAppender".
Now I don't even get that error, but my appender does not get any logs.
Every time I changed the log4j.xml file, I restarted the Designer. I also applied the same changes to log4j.properties and even removed it. It seems that log4j.xml is taking priority anyway.
I also tried to specify the full path of log4j.xml in bwengine.xml for bw.log4j.configuration and adding the two below properties (as shown here) - no effect.
<property>
<name>bw.engine.showInput</name>
<option>bw.log4j.configuration</option>
<default>true</default>
<description>Log4j Configuration file path</description>
</property>
<property>
<name>bw.engine.showOutput</name>
<option>bw.log4j.configuration</option>
<default>true</default>
<description>Log4j Configuration file path</description>
</property>
I'm using BW 5.11 and Designer 5.8.
What am I missing?
Unfortunately this is not possible in Tibco. Only Java activities can be used with custom loggers.
Im using the JOOQ library to generate and perform SQL queries. For debugging reasons I want to see what queries exactly are performed without looking at the changing database every time. I think the jooq framework should show lots of informations about queries and their effects if the log level is set to debug. I use log4j2 for logging, and it is set to debug using the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="DEBUG" packages="ch.fhnw.ima.doggait">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders>
<loggers>
<root level="DEBUG">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>
Unfortunally It looks like JOOQ uses another logger, which is set to info.
This is an example output:
2015-09-29 10:15:04,064 DEBUG Shutdown.. 2015-09-29 10:15:04,065 DEBUG
LoggerCo.. 2015-09-29 10:15:04,111 DEBUG Using d... 10:15:04.116 [Test
worker] DEBUG ch.fh.. Sep 29, 2015 10:15:04 AM
org.jooq.tools.JooqLogger info
INFORMATION:
######################################....
You can see the first few lines are logged in debug mode by log4j2, but Jooq uses JooqLogger in level info.
I load both libraries using gradle:
compile group: 'com.google.inject', name: 'guice-parent', version: '3.0'
compile group: 'com.google.inject.extensions', name: 'guice-persist', version: '3.0'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.8.Final'
compile group: 'com.h2database', name: 'h2', version: '1.4.185'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.0.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.0.2'
compile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.10'
compile group: 'postgresql', name:'postgresql', version:'9.0-801.jdbc4'
compile group: 'org.jooq', name:'jooq', version:'3.6.3'
compile group: 'org.jooq', name:'jooq-meta', version:'3.6.3'
compile group: 'org.jooq', name:'jooq-codegen', version:'3.6.3'
testCompile 'junit:junit:4.11'
Does somebody know why jooq does not use log4j2 as the default logger, or how I can set it to log in debug level?
jOOQ is still using log4j 1.2 as a default, internally. You should use that version (for now), or slf4j instead.
There are a couple of feature requests to improve these dependencies in jOOQ:
#1564 Replace JooqLogger by using slf4j, which already abstracts logger frameworks pretty well
#3280 Expose a new Log SPI, which can be implemented by popular loggers
I know it's little late, but I found the same problem and I fixed it with the help of apache itself.
You can include this adapter in your classpath, it bridges log4j2 with log4j 1.2
log4j-1.2-api-2.6.1.jar
But, you must not have log4j 1.2 jars or config files in your classpath. In short, do everything with log4j2 and just include above jar.
For further reading : http://logging.apache.org/log4j/2.x/faq.html#which_jars
This SO question helped me : Configuring log4j2 and log4j using a single log4j2 xml file
I am using Log4j2 with the Flume appender with the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug" name="ALI" packages="">
<appenders>
<Flume name="eventLogger" suppressExceptions="false" compress="false">
<Agent host="localhost" port="4141"/>
<RFC5424Layout enterpriseNumber="18060" includeMDC="true" appName="com.weather.ali"/>
</Flume>
<RollingFile name="VTECs" fileName="logs/vtecs.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>[%d{ISO8601}] %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="debug">
<appender-ref ref="eventLogger"/>
</root>
<logger name="VTEC" level="debug">
<appender-ref ref="VTECs"/>
</logger>
</loggers>
</configuration>
This works as expected on a couple nodes, but the remaining nodes produce the following error:
ERROR Recursive call to appender eventLogger
Here is the full output of the Log4j bootstrap:
2013-05-07 09:21:59,033 DEBUG Calling createAgent on class org.apache.logging.log4j.flume.appender.Agent for element Agent with params(host="localhost", port="4141")
2013-05-07 09:21:59,040 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.RFC5424Layout for element RFC5424Layout with params(facility="null", id="null", enterpriseNumber="18060", includeMDC="true", mdcId="null", mdcPrefix="null", eventPrefix="null", newLine="null", newLineEscape="null", appName="com.weather.ali", messageId="null", mdcExcludes="null", mdcIncludes="null", mdcRequired="null", charset="null", exceptionPattern="null", Configuration(MyApp))
2013-05-07 09:22:02,148 DEBUG Generated plugins in 3.106963125 seconds
2013-05-07 09:22:02,156 DEBUG Calling createAppender on class org.apache.logging.log4j.flume.appender.FlumeAppender for element Flume with params(agents={host=localhost port=4141}, properties={}, embedded="null", type="null", dataDir="null", connectTimeout="null", requestTimeout="null", agentRetries="null", maxDelay="null", name="eventLogger", suppressExceptions="false", mdcExcludes="null", mdcIncludes="null", mdcRequired="null", mdcPrefix="null", eventPrefix="null", compress="false", batchSize="null", null, RFC5424Layout(facility=LOCAL0 appName=com.weather.ali defaultId=Audit enterpriseNumber=18060 newLine=false includeMDC=true messageId=null), null)
2013-05-07 09:22:02,159 DEBUG Starting FlumeAvroManager FlumeAvro[localhost:4141]
2013-05-07 09:22:02,552 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin for element appenders with params(appenders={eventLogger})
2013-05-07 09:22:06,774 DEBUG Generated plugins in 4.221008626 seconds
2013-05-07 09:22:06,776 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element appender-ref with params(ref="eventLogger", level="null", null)
2013-05-07 09:22:06,778 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element root with params(additivity="null", level="debug", includeLocation="null", appender-ref={org.apache.logging.log4j.core.config.AppenderRef#55ed34f1}, properties={}, Configuration(MyApp), null)
2013-05-07 09:22:06,779 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPlugin for element loggers with params(loggers={root})
2013-05-07 09:22:06,779 DEBUG Shutting down OutputStreamManager SYSTEM_OUT
2013-05-07 09:22:06,779 DEBUG Reconfiguration completed
2013-05-07 09:22:07,237 ERROR Recursive call to appender eventLogger
So two questions:
Why would this work on some nodes and not on others?
I have looked at the code where this error is generated, and it appears to get called whenever the appender code gets called more than once. I see no reason why this should happen. Can someone explain this to me?
This turned out (not surprisingly) to be a flume configuration issue on the affected nodes. The Flume agents on those nodes were not starting properly, and this resulted in the fairly cryptic recursion error.
FYI, for others chasing similar log4j recursion warnings:
https://issues.apache.org/jira/browse/LOG4J2-2738