Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Logging in xtext(Using log4j in Xtext applications)
Logging in xtext [message #647301] Wed, 05 January 2011 10:53 Go to next message
Eclipse UserFriend
Hello,

I have some problems using log4j in my xtext project. I read the following two threads:

1. http://www.laliluna.de/articles/log4j-tutorial.html
2. http://www.eclipse.org/forums/index.php?t=msg&goto=49312 1&
3. http://dev.eclipse.org/newslists/news.eclipse.modeling.tmf/m sg00342.html

None helped me make the logging mechanism work.

Here is what I did:

- I added org.apache.log4j in the Manifest.MF as a dependency
- I created a log4j.properties in the src folder of my plugin (as it is described in 1)
- I called the following statements somewhere in my scoping code:

org.apache.log4j.Logger log = Logger.getLogger(MyClass.class);
log.info("Endpoint: " + currentEnd.getName());


But nothing is happening! I opened the error log view of Eclipse, I checked that it is set to show the information messages, error messages, warnings etc., but nothing is happening...

What am I missing?

Thanks in advance,

Darie
Re: Logging in xtext [message #647326 is a reply to message #647301] Wed, 05 January 2011 11:34 Go to previous messageGo to next message
Eclipse UserFriend
It might be a matter of order. Typically a log4j.properties for log4j.xml might be bundled in a jar on your classpath which is in front of your configuration?

~Karsten
Re: Logging in xtext [message #647399 is a reply to message #647326] Wed, 05 January 2011 20:08 Go to previous messageGo to next message
Eclipse UserFriend
Try something like this:

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="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
 	<param name="Target" value="System.out"/> 
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-4r [%t] %-5p %C{1} %x - %m%n"/> 
    </layout> 
  </appender> 

  <root> 
    <priority value ="info" /> 
    <appender-ref ref="ConsoleAppender" />
  </root>
</log4j:configuration>


Some sample code I use in my plugin...

	// Configure the Apache logger first.
		URL log4jfile = MyHLMPlugin.getDefault().getBundle().getEntry("log4j.xml");
		DOMConfigurator.configure(log4jfile);
		
		// For displaying on the "target" system's console.
		MyHLMConsoleAppender ca = new MyHLMConsoleAppender(new PatternLayout("%-4r [%t] %-5p %C{1} %x - %m%n"), MyHLMConsoleAppender.SYSTEM_CONSOLE);
		ca.setName("MyHLMConsoleAppender");
		ca.activateOptions();
		fLogger.addAppender(ca);


private static final Logger fLogger = MyHLMPlugin.getApacheLogger();



	// Global logger for our plugin.
	private static final Logger fLogger = Logger.getLogge (MyHLMPlugin.class); 

	public static Logger getApacheLogger() {
		return fLogger;
	}



Re: Logging in xtext [message #647477 is a reply to message #647301] Thu, 06 January 2011 10:25 Go to previous messageGo to next message
Eclipse UserFriend
Hello everyone,

thank you for your replies.

I read some more pages (like http://www.torsten-horn.de/techdocs/java-log4j.htm#Simple-Lo gging and http://www.ibm.com/developerworks/library/os-eclog/ ) regarding this matter and didn't manage to get this logging working. I am simply not getting it why Eclipse makes sometimes things seem so complicated.

Well, here's what I tried: please see http://www.javabeat.net/tips/82-baisc-steps-to-configure-log 4j-using-xml-and.html . I followed that tutorial step by step. I created a log4j.properties file with that content and added it to the classpath (together with its containing folder).

Then, I tried calling the logger by simply writing

Logger logger = Logger.getLogger(MyClass.class);
logger.info("Test Log");


But absolutely nothing is happening! Can someone explain to me where this behaviour comes from?

Thanks.


Re: Logging in xtext [message #1864749 is a reply to message #647477] Fri, 05 April 2024 13:32 Go to previous message
Eclipse UserFriend
For anyone still trying to make this work, here is a blog post that explains how to use a plugin fragment for the configuration file to work:https://kinori.tech/blog/en/2023/01/11/logging-in-eclipse-plugins-via-logger-dependency/.

Basically, you need to create a plugin fragment, set the fragment's host to the log4j plugin, and add your configuration file to the classpath of the plugin fragment.
Previous Topic:Standalone Custom Validation Not Being Called
Next Topic:Citizen user learning share : Starting MyDSL project
Goto Forum:
  


Current Time: Wed Jul 09 11:47:31 EDT 2025

Powered by FUDForum. Page generated in 0.04811 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top