FELIX-5108: Applied the patch provided by Stefan (thanks). by default, we don't log to /tmp anymore.
Also, slightly modified the patch in order to enable bnd Reporter traces when log level is >= Info level.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1726715 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/BndLog.java b/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/BndLog.java
index 29e47fc..dd408db 100644
--- a/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/BndLog.java
+++ b/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/BndLog.java
@@ -28,6 +28,7 @@
 
 import org.apache.felix.scrplugin.Log;
 
+import aQute.bnd.osgi.Analyzer;
 import aQute.service.reporter.Reporter;
 
 /**
@@ -51,6 +52,16 @@
 	private final PrintWriter logWriter;
 
 	/**
+	 * The Bnd Analyzer (only used to enable trace mode if at least info log is enabled).
+	 */
+	private final Analyzer analyzer;
+
+	/**
+	 * Was Reporter traces enabled before our plugin is running ?
+	 */
+	private boolean previousTrace;
+
+	/**
 	 * DateFormat used when logging.
 	 */
 	private final static SimpleDateFormat dateFormat = new SimpleDateFormat(
@@ -68,24 +79,33 @@
 	 * 
 	 * @param reporter
 	 *            the bnd logger
-	 * @param logLevel
-	 * @param bsn
+	 * @param analyzer
+	 * @param logToFile
+	 *            Set to false to suppress writing log of plugin action additionally to temp dir.
 	 */
-	BndLog(Reporter reporter, String bsn) {
+	BndLog(Reporter reporter, Analyzer analyzer, boolean logToFile) {
 		this.reporter = reporter;
-		File logFilePath = new File(System.getProperty("java.io.tmpdir")
-				+ File.separator + "scrplugin" + File.separator + bsn + ".log");
-		new File(logFilePath.getParent()).mkdirs();
-		
-		PrintWriter writer = null;
-		try {
-			writer = new PrintWriter(new FileWriter(logFilePath, false));
-		} catch (IOException e) {
-			reporter.exception(e, "Could not create scrplugin log file: %s",
-					logFilePath);
-			writer = null;
-		}
-		this.logWriter = writer;
+		this.analyzer = analyzer;
+		String bsn = analyzer.getBsn();
+        
+        if (logToFile) {
+            File logFilePath = new File(System.getProperty("java.io.tmpdir")
+            		+ File.separator + "scrplugin" + File.separator + bsn + ".log");
+            new File(logFilePath.getParent()).mkdirs();
+            
+            PrintWriter writer = null;
+            try {
+            	writer = new PrintWriter(new FileWriter(logFilePath, false));
+            } catch (IOException e) {
+            	reporter.exception(e, "Could not create scrplugin log file: %s",
+            			logFilePath);
+            	writer = null;
+            }
+            this.logWriter = writer;
+        }
+        else {
+            this.logWriter = null;
+        }
 	}
 
 	/**
@@ -95,6 +115,9 @@
 		if (logWriter != null) {
 			logWriter.close();
 		}
+		if (this.logEnabled.ordinal() >= Level.Info.ordinal()) {
+			this.analyzer.setTrace(this.previousTrace);
+		}		
 	}
 
 	/**
@@ -108,6 +131,11 @@
 			level = Character.toUpperCase(level.charAt(0))
 					+ level.substring(1).toLowerCase();
 			this.logEnabled = Level.valueOf(level);
+			if (this.logEnabled.ordinal() >= Level.Info.ordinal()) {
+				// We have to enable traces, if not the bnd reporter won't log info or debug messages.
+				this.previousTrace = analyzer.isTrace();
+				analyzer.setTrace(true);
+			}
 		} catch (IllegalArgumentException e) {
 			this.logEnabled = Level.Warn;
 			warn("Bnd scrplugin logger initialized with invalid log level: "
diff --git a/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java b/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java
index aab84d9..10ef4f7 100644
--- a/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java
+++ b/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java
@@ -84,6 +84,11 @@
 	 */
 	private static final String LOGLEVEL = "log";
 
+    /**
+     * "logToFile" parameter, which may be set to false to suppress writing log of plugin action additionally to temp dir. Default: true.
+     */
+    private static final String LOGTOFILE = "logToFile";
+
 	/**
 	 * The name of the directory where the descriptor files are generated into.
 	 */
@@ -141,7 +146,8 @@
 	 * Scan scr or ds annotation from the target jar.
 	 */
 	public boolean analyzeJar(Analyzer analyzer) throws Exception {
-		this.log = new BndLog(reporter, analyzer.getBsn());
+		this.log = new BndLog(reporter, analyzer,
+		        parseOption(properties, LOGTOFILE, false));
 
 		try {
 			init(analyzer);