Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Logging in Virgo 3.0.0.M05
Logging in Virgo 3.0.0.M05 [message #682190] Fri, 10 June 2011 15:16 Go to next message
Raji Abraham is currently offline Raji AbrahamFriend
Messages: 13
Registered: October 2010
Junior Member
I am confused with the way logging is supposed to work under Virgo. The 3.0 doc states

Quote:
Virgo Web Server uses SLF4J interfaces to Logback, and the root logger (by default) captures all logging output and appends it to the application-specific trace files as described above.


I understand this statement as the way it effectively worked under Spring Dm 1.0.2.
However, all of the logging continues to appear in serviceability/logs/virgo-server/log.log. If I add a logback.xml file in the root of my bundle, then I see the logs appear in the file path I specify in logback.xml.

The M05 release document states Quote:
Bug 342716: Support the OSGi Log Service and plumb it in to Virgo's logging infrastructure

This too is not working for me.

I have attached a simple bundle with one class that tests these functionality. Not sure what I am missing.

package com.ensarc.test;

import java.util.Date;

import org.osgi.service.log.LogService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class TestLogging {

	@Autowired
	private LogService logService;	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	@Scheduled(fixedDelay=5000)
	public void logInfo() {		
		System.out.println("Logging Sysout Info : " + new Date()); // appears in the main log		
		logger.info("Logging SLF4J Info : " + new Date()); // appears in the main log or application log if logback.xml in bundle
		logService.log( LogService.LOG_INFO, "Logging OSGI Info : " + new Date() ); // appears nowhere.
	}

	@Scheduled(fixedDelay=10000)
	public void logError() {
		System.err.println("Logging Syserr Info : " + new Date()); // appears in the main log		
		logger.error("Logging SLF4J Error : " + new Date()); // appears in the main log or application log if logback.xml in bundle		
		logService.log( LogService.LOG_ERROR, "Logging OSGI Error : " + new Date() ); // appears nowhere.
	}
}


<?xml version="1.0" encoding="UTF-8"?>
<beans ....>

	<context:component-scan base-package="com.ensarc.test" />
	<task:annotation-driven />

	<osgi:reference id="logService" interface="org.osgi.service.log.LogService" />
</beans>


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.ensarc.log.test
Bundle-SymbolicName: com.ensarc.log.test
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.slf4j,
  org.osgi.service.log
Import-Library: org.springframework.spring

ENVIRONMENT
Windows 7 Pro 64 bit
JDK 1.6.17

To run: Unzipped the Virgo 3.0.0.M05 and copied my bundle to the pickup directory - no additional Jars were introduced.

Thanks
Raji
Re: Logging in Virgo 3.0.0.M05 [message #682198 is a reply to message #682190] Fri, 10 June 2011 15:34 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

I'll have a look at this as I did the LogService work, thanks for providing a test bundle.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Logging in Virgo 3.0.0.M05 [message #683791 is a reply to message #682198] Tue, 14 June 2011 12:39 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

So on the first point, this is working as designed. All logging will go in the main log file unless you configure it otherwise. The logback file you are using is sending it else where. It's recommended however that you don't add logback config to your own bundles and instead just configure the main logback.xml in the config directory.

As for the OSGi logging service, it looks like there are two available and one of them doesn't do anything and you are binding to that one. I have put a fix in the code and it will be in the next shipping.

Hope that help, please come back if you still have questions.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Logging in Virgo 3.0.0.M05 [message #683891 is a reply to message #683791] Tue, 14 June 2011 15:48 Go to previous messageGo to next message
Raji Abraham is currently offline Raji AbrahamFriend
Messages: 13
Registered: October 2010
Junior Member
Chris,

Appreciate your time in looking at this. Yes, I do not want to add logback config in each bundle. If its working as designed, then I believe it is not working as documented. Let me quote the docs again:

Quote:
By default, the VWS trace file is called $SERVER_HOME/serviceability/logs/log.log, and, again by default, the application trace files are called $SERVER_HOME/serviceability/logs/application_name/log.log, where application_name is automatically set by VWS for each application artifact installed and run (it is a combination of the artifact name and the version).


The config/serviceablity.xml file has the following entry "out of the box":

<appender name="SIFTED_LOG_FILE" class="ch.qos.logback.classic.sift.SiftingAppender">
	<discriminator>
		<Key>applicationName</Key>
		<DefaultValue>virgo-server</DefaultValue>
	</discriminator>
	<sift>
		<appender name="${applicationName}_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
			<file>serviceability/logs/${applicationName}/log.log</file>
			<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
				<FileNamePattern>serviceability/logs/${applicationName}/log_%i.log</FileNamePattern>
				<MinIndex>1</MinIndex>
				<MaxIndex>4</MaxIndex>
			</rollingPolicy>
			<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
				<MaxFileSize>10MB</MaxFileSize>
			</triggeringPolicy>
			<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
				<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level %-28.28thread %-64.64logger{64} %X{medic.eventCode} %msg %ex%n</Pattern>
			</encoder>
		</appender>
	</sift>
</appender>


Without changing anything in this file, I was able to achieve what I want by adding the following code to my bundle:

MDC.put("applicationName", "my.bundle.name");


Now the output from System.err, System.out and the specific logging code is directed to the serviceability/logs/my.bundle.name/log.log. I thought the document implied that VWS is setting the MDC (or something else) to make this happen automatically. Is that not true?

Thanks
Raji
Re: Logging in Virgo 3.0.0.M05 [message #685491 is a reply to message #683891] Fri, 17 June 2011 15:59 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

So with the LogService fix in place I have the following happening with your application deployed.

SLF4J logging goes in the per-app log file and the sys and logservice logging goes in the main log file.

I have checked the intended behavior with my team mate and it should be as follows. By default per-app logging should only occur for web bundles, scoped plans and pars. Nothing else should get it's own logging file. In every case all logging should go in the main log file in addition to any per app log files that are being appended to.

There may be some improvements required to the way we split logging out to the per-app file. Certainly the SLF4J logging service is the best one to use. It's also interesting that your configuration produces a logging file with a name that doesn't have the version in it.

Could you create a bugzilla (https://bugs.eclipse.org/bugs/enter_bug.cgi under RT/Virgo) with your sample app and referencing this forum thread so that some propper time gets spent on this. We certainly want to get this straight before 3.0 goes out.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Logging in Virgo 3.0.0.M05 [message #685987 is a reply to message #685491] Tue, 21 June 2011 09:38 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=349916

------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Logging in Virgo 3.0.0.M05 [message #688498 is a reply to message #685987] Fri, 24 June 2011 19:52 Go to previous messageGo to next message
Raji Abraham is currently offline Raji AbrahamFriend
Messages: 13
Registered: October 2010
Junior Member
Chris,

Thanks for looking at this further. I did not get the thread-updated email and hence was late in creating the bugzilla entry. Too many website to keep checking on a regular week Surprised

I think if the same is mentioned in the documentation, that will help others, especially with the difference between scoped and global plans - that is less intuitive for someone new to plan concepts.

For now I have the following class in one of my package and an entry for the bean to get the desired effect.

package my.package;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.MDC;
import org.springframework.osgi.context.BundleContextAware;

/**
 * This class is simply to set the MDC so that the LogBack service can sift logs to a separate file
 * 
 * @author Raji
 *
 */
public class SimpleClass implements BundleContextAware {
	
	@Override
	public void setBundleContext(BundleContext bndCtx) {
		Bundle bndl = bndCtx.getBundle();
		String name = bndl.getSymbolicName();
		String ver = bndl.getVersion().toString();
		MDC.put("applicationName", name + "-" + ver);		
	}
}


	<bean class="my.package.SimpleClass" />


Thanks
Raji

[Updated on: Fri, 24 June 2011 20:50]

Report message to a moderator

Re: Logging in Virgo 3.0.0.M05 [message #689877 is a reply to message #688498] Tue, 28 June 2011 14:31 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

I have made improvements to the documentation for this. I tried your test bundle and a couple variations of it on Virgo and it is all working as designed. Bug closed.

Making that call to MDC will indeed work but I'd recommend sticking to SLF4J for all your logging within your application or simply referencing you bundle from a scoped plan and let Virgo do the per app configuration behind the scenes.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Logging in Virgo 3.0.0.M05 [message #689910 is a reply to message #689877] Tue, 28 June 2011 15:19 Go to previous messageGo to next message
Raji Abraham is currently offline Raji AbrahamFriend
Messages: 13
Registered: October 2010
Junior Member
Chris,
Appreciate your effort in updating the documents. I do not want to deviate from using the SLF4J logging. For typical applications I will be relying on the scoped plan logging. But for common utility plans (see thread: http://www.eclipse.org/forums/index.php/mv/msg/215568/689382/#msg_689382) I don't have a choice but to rely on the MDC call right now or do I?

Thanks
Raji
Re: Logging in Virgo 3.0.0.M05 [message #690117 is a reply to message #689877] Wed, 29 June 2011 02:32 Go to previous message
Raman Gupta is currently offline Raman GuptaFriend
Messages: 12
Registered: December 2010
Junior Member
Christopher Frost wrote on Tue, 28 June 2011 10:31
I have made improvements to the documentation for this.


[cross-posted to Bugzilla]

There is one key item you mentioned on the forum that AFAICS is not in the docs, and that is this statement:

"By default per-app logging should only occur for web bundles, scoped plans and pars."

I think this is an important distinction. I had several non-scoped plans and did not understand why the per-app logging was not working until I read that statement in the forum.

Cheers,
Raman
Previous Topic:Problem launching Virgo WS
Next Topic:Virgo Kernel turns off MBeanServer creation
Goto Forum:
  


Current Time: Sat Dec 20 18:07:02 GMT 2014

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

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