Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Logging in xtext(Using log4j in Xtext applications)
Logging in xtext [message #647301] Wed, 05 January 2011 15:53 Go to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
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 16:34 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

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


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Logging in xtext [message #647399 is a reply to message #647326] Thu, 06 January 2011 01:08 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
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 15:25 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
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 17:32 Go to previous message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

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.


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Previous Topic:Standalone Custom Validation Not Being Called
Next Topic:Citizen user learning share : Starting MyDSL project
Goto Forum:
  


Current Time: Sat May 25 11:26:20 GMT 2024

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

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

Back to the top