Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Integrate log4J Logging
Integrate log4J Logging [message #543503] Tue, 29 June 2010 15:40 Go to next message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
Hello,

i use in my RCP application log4j as Logger and want now integrate the logging information in the console, inside the application.

The console integration was successful and very easy,
ich have paste the following code in the perspecitve:
final MessageConsole myConsole = new MessageConsole("Console", null); 
        ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { myConsole });
        final MessageConsoleStream stream = myConsole.newMessageStream();

        final PrintStream myS = new PrintStream(stream);
        System.setOut(myS); 
        System.setErr(myS); 


If i use in my code "System.out.println" then i see the logg information in my integrated console. But i dont see the log4j logging. Is here an Appender needed??
Or is my log4j.properties file wrong?
heres the input:
log4j.rootCategory=debug, stdout, R

# Print only messages of priority WARN or higher for your category
log4j.category.your.category.name=warn
# Specifically inherit the priority level
#log4j.category.your.category.name=INHERITED

#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} Time:%-4r %-5p [%t] %M (%F:%L) - %m%n
#%5p [%t] (%F:%L) - %m%n

#### Second appender writes to a file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:\\temp\\log\\logfile.txt

# Control the maximum log file size
log4j.appender.R.MaxFileSize=500KB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} Time:%-4r %-5p [%t] %M (%F:%L) - %m%n


It would be nice, if someone could help me.
Re: Integrate log4J Logging [message #543989 is a reply to message #543503] Thu, 01 July 2010 09:46 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe FondacciFriend
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello,

You definitely need to implement a custom appender skeleton which needs to extend AppenderSkeleton.

Then in your append method, you need to have this kind of code :
		@Override
		protected void append(LoggingEvent arg0) {
			// If you want to bufferize logs before console creation
			if(console==null) {
				consoleBuffer.append(getLayout().format(arg0));
				return;
			}
			try {
				if(stream==null) {
					stream = console.newMessageStream();
				}
				if(stream!=null && !stream.isClosed()) {
					stream.write(getLayout().format(arg0));
				}
			} catch(IOException e) {
				// Only debugging as this might append when disposing workbench
				log.debug(e);
			}
		}


Regards,
Christophe
http://www.nextep-softwares.com
Re: Integrate log4J Logging [message #547641 is a reply to message #543989] Mon, 19 July 2010 09:00 Go to previous message
budili Missing name is currently offline budili Missing nameFriend
Messages: 64
Registered: May 2010
Member
I have try it, but not successful.

I have wrote the log4j skeleton appender, without success.
Are there some constraints which i have to attend?
Maybe the log4.properties?
The console integration works fine, if i use the System.out.println, i get the logs in my console, but not if i use log.4 - logging.
Previous Topic:Can I put a view into the editor area?
Next Topic:autosave snapshot
Goto Forum:
  


Current Time: Thu Apr 25 23:44:21 GMT 2024

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

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

Back to the top