0

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.

Community
  • 1
  • 1
  • You need to tell us what's your configuration is like. – glee8e Jan 10 '17 at 12:39
  • Which configuration? I do not configure log4j, I only use the BasicConfigurator.configure() command. – ConveniencePatterns Jan 10 '17 at 12:44
  • Possible duplicate of [How do I increase the capacity of the Eclipse output console?](http://stackoverflow.com/questions/2828255/how-do-i-increase-the-capacity-of-the-eclipse-output-console) – glee8e Jan 10 '17 at 12:47
  • Oh, that's not a typical case. Sorry for missing that. I didn't saw that line. Try the above link. It's the root cause of broken eclipse console. It may fix other bugs, though I'm not certain. Btw, what's your previous logging is like? – glee8e Jan 10 '17 at 12:48
  • I unchecked "Limit console output", but that changed nothing. – ConveniencePatterns Jan 10 '17 at 12:55
  • 1
    Well, well, well. It's my fault. I shouldn't have been doing these before having breakfast. AFAIK eclipse should have nothing to do with this. Did you added a new dependency? What kind of logging framework do they use, or do they introduce new logging framework to your dependency hierarchy? They may all trigger a change on logging behavior. – glee8e Jan 10 '17 at 13:07
  • I added my dependencies to the post. Also I downloaded a clean Eclipse version and that fixed the problem. But using the clean version would mean to install manually all the plugins and tools again. Also I would have to configure my preferences from scratch. – ConveniencePatterns Jan 10 '17 at 13:17
  • 1
    You should mention you are building a OSGi app using equinox. I was just thinking all sort of weird situations you may get in, but not a weird OSGi issue. I've suggested an edit to add those tags and to change the title. – glee8e Jan 11 '17 at 11:23
  • From my poor OSGi knowledge, I think when PDT launch a plugin, its dependencies, if not configured explicitly, are all loaded from eclipse's own bundle repositories (or what ever it is called). It may be a weird bug during the process, or a modified jar. – glee8e Jan 11 '17 at 11:28

1 Answers1

1

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);
}
Happy
  • 26
  • 4