Logging in Virgo 3.0.0.M05 [message #682190] |
Fri, 10 June 2011 11:16  |
Eclipse User |
|
|
|
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 #683891 is a reply to message #683791] |
Tue, 14 June 2011 11:48   |
Eclipse User |
|
|
|
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 #690117 is a reply to message #689877] |
Tue, 28 June 2011 22:32  |
Eclipse User |
|
|
|
Christopher Frost wrote on Tue, 28 June 2011 10:31I 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
|
|
|
Powered by
FUDForum. Page generated in 0.35126 seconds