Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 127CDD362 for ; Tue, 16 Oct 2012 07:47:48 +0000 (UTC) Received: (qmail 5770 invoked by uid 500); 16 Oct 2012 07:47:47 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 5593 invoked by uid 500); 16 Oct 2012 07:47:42 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 5522 invoked by uid 99); 16 Oct 2012 07:47:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2012 07:47:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2012 07:47:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5A6EE2388A3D; Tue, 16 Oct 2012 07:46:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1398686 - /sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java Date: Tue, 16 Oct 2012 07:46:49 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121016074649.5A6EE2388A3D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Tue Oct 16 07:46:48 2012 New Revision: 1398686 URL: http://svn.apache.org/viewvc?rev=1398686&view=rev Log: SLING-2622 Control framework logging sending the output through Sling's MainDelegate output formatting instead of leaving it up to the framework to format. Also make sure log messages are not overlapping in the output if logging is called concurrently. Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java?rev=1398686&r1=1398685&r2=1398686&view=diff ============================================================================== --- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java (original) +++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/app/MainDelegate.java Tue Oct 16 07:46:48 2012 @@ -33,7 +33,9 @@ import org.apache.sling.launchpad.base.i import org.apache.sling.launchpad.base.shared.Launcher; import org.apache.sling.launchpad.base.shared.Notifiable; import org.apache.sling.launchpad.base.shared.SharedConstants; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; +import org.osgi.framework.ServiceReference; /** * The Main class is a simple Java Application which interprests @@ -156,7 +158,7 @@ public class MainDelegate implements Lau DEFAULT_LOG_LEVEL); commandLine.put(LOG_LEVEL_PROP, String.valueOf(logLevel)); } - final Logger logger = new Logger(); + final Logger logger = new SlingLogger(); // Display port number on console, in case HttpService doesn't info("HTTP server port: " + commandLine.get(PROP_PORT), null); @@ -320,11 +322,21 @@ public class MainDelegate implements Lau System.exit(code); } + // emit an debugging message to standard out + static void debug(String message, Throwable t) { + log(System.out, "*DEBUG*", message, t); + } + // emit an informational message to standard out static void info(String message, Throwable t) { log(System.out, "*INFO *", message, t); } + // emit an warning message to standard out + static void warn(String message, Throwable t) { + log(System.out, "*WARN *", message, t); + } + // emit an error message to standard err static void error(String message, Throwable t) { log(System.err, "*ERROR*", message, t); @@ -347,19 +359,55 @@ public class MainDelegate implements Lau linePrefixBuilder.append("] "); final String linePrefix = linePrefixBuilder.toString(); - out.print(linePrefix); - out.println(message); - if (t != null) { - t.printStackTrace(new PrintStream(out) { - @Override - public void println(String x) { - synchronized (this) { - print(linePrefix); - super.println(x); - flush(); + synchronized (out) { + out.print(linePrefix); + out.println(message); + if (t != null) { + t.printStackTrace(new PrintStream(out) { + @Override + public void println(String x) { + synchronized (this) { + print(linePrefix); + super.println(x); + flush(); + } } - } - }); + }); + } + } + } + + private static class SlingLogger extends Logger { + + @Override + protected void doLog(Bundle bundle, ServiceReference sr, int level, String msg, Throwable throwable) { + + // unwind throwable if it is a BundleException + if ((throwable instanceof BundleException) && (((BundleException) throwable).getNestedException() != null)) { + throwable = ((BundleException) throwable).getNestedException(); + } + + String s = (sr == null) ? null : "SvcRef " + sr; + s = (s == null) ? null : s + " Bundle '" + bundle.getBundleId() + "'"; + s = (s == null) ? msg : s + " " + msg; + s = (throwable == null) ? s : s + " (" + throwable + ")"; + + switch (level) { + case LOG_DEBUG: + debug("DEBUG: " + s, null); + break; + case LOG_INFO: + info("INFO: " + s, null); + break; + case LOG_WARNING: + warn("WARNING: " + s, null); + break; + case LOG_ERROR: + error("ERROR: " + s, throwable); + break; + default: + warn("UNKNOWN[" + level + "]: " + s, null); + } } } }