Revision: 603
http://japi.svn.sourceforge.net/japi/?rev=603&view=rev
Author: christianhujer
Date: 2007-09-08 13:23:33 -0700 (Sat, 08 Sep 2007)
Log Message:
-----------
Improved setting the log level, added setting the log configuration. This is still beta. Use with care.
Modified Paths:
--------------
libs/argparser/trunk/src/net/sf/japi/io/args/LogCommand.java
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/LogCommand.java
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/LogCommand.java 2007-09-08 20:22:46 UTC (rev 602)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/LogCommand.java 2007-09-08 20:23:33 UTC (rev 603)
@@ -19,7 +19,12 @@
package net.sf.japi.io.args;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.logging.Level;
+import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
@@ -47,11 +52,29 @@
/** Sets the log level to log.
* @param level LogLevel to log.
*/
- @Option({"l", "level"})
+ @Option({"l", "loglevel"})
public void setLevel(@NotNull final Level level) {
- log.setLevel(level);
+ try {
+ LogManager.getLogManager().readConfiguration(new ByteArrayInputStream((".level=" + level + "\nhandlers=java.util.logging.ConsoleHandler\njava.util.logging.ConsoleHandler.level=" + level).getBytes()));
+ } catch (final IOException e) {
+ assert false : "This should never happen because we're reading from RAM.";
+ }
}
+ /** Initializes the logging system from a properties file.
+ * @param filename Filename of the file to initialize the logging system with.
+ * @throws IOException In case of I/O problems reading the properties file.
+ */
+ @Option({"L", "logconfig"})
+ public void setLogConfig(@NotNull final String filename) throws IOException {
+ final InputStream in = new FileInputStream(filename);
+ try {
+ LogManager.getLogManager().readConfiguration(in);
+ } finally {
+ in.close();
+ }
+ }
+
/** Returns the logger.
* @return The Logger.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|