I use Log4j and I import OpenNLP via Maven. Now I want to disable the log output (in red) which is printed in syso from opennlp.
I tried to add to my log4j.properties:
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.org.opennlp=OFF
The last line should hide opennlp messages such as:
Average: 1000,0 sent/s
Total: 1 sent
Runtime: 0.001s
but does not work. Please tell me why?
OpenNLP is not using Log4j, or any other logging framework. The command line interface prints directly to stdout. The command line tools are only useful for training/evaluating and testing.
For production use you should integrate OpenNLP via its Java API, or via some other framework like Apache UIMA.
Related
I am using log4j with very simple setup in an Eclipse plugin project, that I am building right now.
I call BasicConfigurator.configure(); in the main class and then just use log4j in every class like this:
private static final Logger logger= LogManager.getLogger(ClassName.class.getName());
That worked fine for a while but now I have problems with log4j. I am not sure what happened, but it seems the logging level is now Level.WARN. Also the console output is somewhat broken. The logging messages are logged two times each. One time normal, and one time really weird:
!ENTRY org.apache.log4j 2 0 2017-01-10 13:19:58.192
!MESSAGE package.ClassName - This is a logging message
0 [main] WARN package.ClassName - This is a logging message
I do not use a properties or xml file so I cannot imagine what I changed.
EDIT: I checked out an older point of the program and the problem still exists. That should mean it is not a problem of the code itself. Can Eclipse settings or something like that affect the console behavior?
EDIT 2: The idea of unchecking "Limit console output" did not help.
EDIT 3: These are my dependencies:
Require-Bundle: org.eclipse.ui,
org.eclipse.emf.ecore;bundle-version="2.12.0",
org.eclipse.emf.ecore.xmi;bundle-version="2.12.0",
org.eclipse.core.resources;bundle-version="3.11.0",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.jdt.core;bundle-version="3.12.1",
org.eclipse.jdt.launching;bundle-version="3.8.100",
org.junit,
org.apache.log4j;bundle-version="1.2.15"
EDIT 4: A clean Eclipse version fixes the output problem. But using the clean version would mean to install again all the plugins and tools. Also I would have to configure my preferences from scratch. Also perhaps that then causes the problem again, so I should rather find the cause of the problem.
Try removing the "trace_file" directive from the my_package logger statement.
Try this one
static {
PatternLayout layout = new PatternLayout();
String conversionPattern = "%d %-5p [%t] %c{2} (%2F:%M(%L)):%m%n";
layout.setConversionPattern(conversionPattern);
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.setLayout(layout);
consoleAppender.activateOptions();
Logger rootLogger = Logger.getRootLogger();
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(consoleAppender);
}
I'm running an Oozie Java workflow (the jar file is in HDFS), and I'd like to add logging functionality to my application. Does anybody know how to do it? Where should I put my "log4j.properties" file? How can I make log4j to output the log to a location in HDFS?
Looking in this documentation, you can try adding oozie-log4j.properties in your oozie directory (where workflow.xml is).
Here are the default settings:
log4j.appender.oozie=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.oozie.RollingPolicy=org.apache.oozie.util.OozieRollingPolicy
log4j.appender.oozie.File=${oozie.log.dir}/oozie.log
log4j.appender.oozie.Append=true
log4j.appender.oozie.layout=org.apache.log4j.PatternLayout
log4j.appender.oozie.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n
log4j.appender.oozie.RollingPolicy.FileNamePattern=${log4j.appender.oozie.File}-%d{yyyy-MM-dd-HH}
log4j.appender.oozie.RollingPolicy.MaxHistory=720
It also outlines the following restrictions:
In order for Oozie logging to work 100% correctly, the following restrictions must be observed (described below and in the oozie-log4j.properties file):
The appender that Oozie uses must be named "oozie" (i.e. log4j.appender.oozie )
log4j.appender.oozie.RollingPolicy.FileNamePattern must end with "-%d{yyyy-MM-dd-HH}.gz" or "-%d{yyyy-MM-dd-HH}". If it ends with ".gz" the old logs will be compressed when rolled
log4j.appender.oozie.RollingPolicy.FileNamePattern must start with the value of log4j.appender.oozie.File
I hava jar with class my.package.Foo inside, containing main method.
What is more i have Log4j configurated as a logging system.
I want to print full stack trace while exception is catched, however i read this topic: log4j not printing the stacktrace for exceptions
and i think that i need to use a -XX:-OmitStackTraceInFastThrow flag.
So i'm trying to call my app with command line like this:
java -XX:-OmitStackTraceInFastThrow -cp %JAR_LOCATION:% my.package.Foo
However i'm still missing stacktrace, i get only short exception message.
Here is my log4j config:
log4j.rootLogger=INFO, CONSOLE, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=log.txt
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{HH:mm:ss.SSS} %-4p %c{2}.%m%n
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-4p %c{2}.%m%n
What i'm missing?
Try it like this:
set JAR_LOCATION=c:\any folder with spaces\jar
java -XX:-OmitStackTraceInFastThrow -cp "%JAR_LOCATION:~%" my.package.Foo
You have to remove the ":" char from %JAR_LOCATION:%, or use %JAR_LOCATION:~% to de-quote it, and quote it directly at the JAVA command, because the path probably contains spaces.
I use SLF4J in my game server project which uses Slf4j and Log4j. However netty specific logs come out like below.
2013-06-08 13:37:30,254 [Slf4JLogger.java:71][DEBUG]:Using SLF4J as the default logging framework
2013-06-08 13:37:30,261 [Slf4JLogger.java:71][DEBUG]:Platform: Windows
2013-06-08 13:37:30,270 [Slf4JLogger.java:76][DEBUG]:Java version: 7
2013-06-08 13:37:30,273 [Slf4JLogger.java:76][DEBUG]:java.nio.ByteBuffer.cleaner: available
2013-06-08 13:37:30,274 [Slf4JLogger.java:76][DEBUG]:java.nio.Buffer.address: available
2013-06-08 13:37:30,274 [Slf4JLogger.java:76][DEBUG]:sun.misc.Unsafe.theUnsafe: available
2013-06-08 13:37:30,275 [Slf4JLogger.java:71][DEBUG]:sun.misc.Unsafe.copyMemory: available
2013-06-08 13:37:30,276 [Slf4JLogger.java:76][DEBUG]:java.nio.Bits.unaligned: true
2013-06-08 13:37:30,276 [Slf4JLogger.java:76][DEBUG]:sun.misc.Unsafe: available
2013-06-08 13:37:30,278 [Slf4JLogger.java:71][DEBUG]:Javassist: unavailable
They dont show the actual netty class and package information. My corresponding Log4j pattern is:
log4j.appender.toLogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.toLogFile.layout.ConversionPattern= %d [%F:%L][%p]:%m%n
What am I configuring wrong here?
Try to use %c instead of %F in your pattern. %F - Outputs the file name where the logging request was issued and %c prints logger name. In Netty all logging goes through the wrapper classes in your case it's Slf4JLogger.class
Your pattern should look like:
log4j.appender.toLogFile.layout.ConversionPattern= %d [%c:%L][%p]:%m%n
EDIT due to comment:
Yes there is a way to print only filename:
%c{1}
See documentation:
http://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns
I am looking for a way to direct all the jetty 7 logging to syslog. My current configuration
dumps everything to JETTY_HOME/logs/.. After some initial ivestigation, it seems I should change JETTY_HOME/etc/jetty-logging.xml, but this does not look straightforward. It looks like I should create a new PrintStream implementation which sends its output to syslog and redirecting stderr and stdout to that class in jetty-logging.xml.
any easier way to do that or to make jetty log directly to log4j ?
Thanks
According to this advice by David Yu, it should be as simple as making org.slf4j.Logger available, which didn't work for me. However, in unix you could do something like
java ... -Djetty.home=/usr/share/jetty -Djava.io.tmpdir=/tmp \
-jar /usr/share/jetty/start.jar /usr/share/jetty/etc/jetty.xml 2>&1 |
logger -t jetty
In etc/jetty.xml, you may also want to comment out the line that calls RequestLogImpl.setFilename.