User: mulder
Date: 00/09/15 14:14:15
Modified: src/main/org/jboss/logging FileLogging.java
FileLoggingMBean.java ViewerLogging.java
Log:
Make file and GUI loggers work. Not sure why they were disabled before.
Revision Changes Path
1.5 +49 -35 jboss/src/main/org/jboss/logging/FileLogging.java
Index: FileLogging.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/logging/FileLogging.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileLogging.java 2000/09/08 20:20:38 1.4
+++ FileLogging.java 2000/09/15 21:14:14 1.5
@@ -7,6 +7,7 @@
package org.jboss.logging;
import java.io.*;
+import java.net.URL;
import java.text.*;
import java.util.Date;
import java.util.SortedSet;
@@ -16,78 +17,78 @@
import javax.management.*;
/**
- *
+ *
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class FileLogging
implements FileLoggingMBean, MBeanRegistration, NotificationListener
{
// Constants -----------------------------------------------------
public static final String OBJECT_NAME =
"DefaultDomain:service=Logging,type=File";
-
+
// Attributes ----------------------------------------------------
PrintStream out, err;
DateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd hh.mm");
String format = "<{0}><{2}> {4}";
MessageFormat msgFmt = new MessageFormat(format);
-
+
boolean verbose = false;
-
+
Log log = new Log("File logging");
-
+
String filter = "Information,Debug,Warning,Error";
String logName = "server.log";
String sources;
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public FileLogging()
{
}
-
+
public FileLogging(String filter, String format)
{
this.filter = filter;
setFormat(format);
}
-
+
public FileLogging(String filter, String format, String sources, String fileName)
{
this.filter = filter;
setFormat(format);
-
+
this.sources = sources;
this.logName = fileName;
}
-
+
// Public --------------------------------------------------------
- public void setFormat(String format)
- {
- this.format = format;
+ public void setFormat(String format)
+ {
+ this.format = format;
msgFmt = new MessageFormat(format);
}
public String getFormat() { return format; }
-
- public void setLogName(String logName)
- {
- this.logName = logName;
-
- if (out != null)
- {
- out.close();
- out = null;
+
+ public void setLogName(String logName) throws FileNotFoundException
+ {
+ if(!logName.equals(this.logName)) {
+ this.logName = logName;
+
+ if (out != null)
+ out = null;
+ openLogFile();
}
}
public String getLogName() { return logName; }
-
+
// NotificationListener implementation ---------------------------
public void handleNotification(Notification n,
java.lang.Object handback)
{
- if (sources == null || sources.indexOf(n.getUserData().toString()) != -1)
+ if (sources == null || sources.length() == 0 ||
sources.indexOf(n.getUserData().toString()) != -1)
{
if (filter.indexOf(n.getType()) != -1)
{
@@ -97,34 +98,47 @@
}
}
}
-
+
// MBeanRegistration implementation ------------------------------
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws java.lang.Exception
{
try
{
- out = new PrintStream(new FileOutputStream(new File(new
File(getClass().getResource("/log.properties").getFile()).getParent(), logName)));
-
+ openLogFile();
server.addNotificationListener(new
ObjectName(server.getDefaultDomain(),"service","Log"),this,null,null);
-
+
log.log("Logging started");
return new ObjectName(OBJECT_NAME);
-
+
} catch (Throwable e)
{
Logger.exception(e);
}
return new ObjectName(OBJECT_NAME);
}
-
- public void postRegister(java.lang.Boolean registrationDone)
+
+ public void postRegister(java.lang.Boolean registrationDone)
{
}
-
+
public void preDeregister()
- throws java.lang.Exception
+ throws java.lang.Exception
{}
-
+
public void postDeregister() {}
+
+ // Private --------------------------------------------------
+ private void openLogFile() throws FileNotFoundException {
+ URL properties = getClass().getResource("/log.properties");
+ if(properties == null)
+ System.err.println("Unable to identify logging directory!");
+ File parent = new File(properties.getFile()).getParentFile();
+ File logFile = new File(parent, logName);
+ try {
+ out = new PrintStream(new FileOutputStream(logFile.getCanonicalPath(),
false));
+ } catch (IOException e) {
+ throw new FileNotFoundException(e.getMessage());
+ }
+ }
}
1.2 +4 -4 jboss/src/main/org/jboss/logging/FileLoggingMBean.java
Index: FileLoggingMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/logging/FileLoggingMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileLoggingMBean.java 2000/04/22 14:30:13 1.1
+++ FileLoggingMBean.java 2000/09/15 21:14:14 1.2
@@ -7,17 +7,17 @@
package org.jboss.logging;
/**
- *
+ *
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface FileLoggingMBean
{
// Constants -----------------------------------------------------
-
+
// Public --------------------------------------------------------
- public void setLogName(String logName);
+ public void setLogName(String logName) throws java.io.FileNotFoundException;
public String getLogName();
}
1.3 +28 -27 jboss/src/main/org/jboss/logging/ViewerLogging.java
Index: ViewerLogging.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/logging/ViewerLogging.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ViewerLogging.java 2000/05/30 18:32:28 1.2
+++ ViewerLogging.java 2000/09/15 21:14:14 1.3
@@ -9,46 +9,47 @@
import java.awt.*;
import java.io.*;
import java.text.*;
+import java.util.*;
import javax.management.*;
import javax.swing.*;
import javax.swing.table.*;
/**
- *
+ *
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ViewerLogging
implements ViewerLoggingMBean, MBeanRegistration, NotificationListener
{
// Constants -----------------------------------------------------
-
+
// Attributes ----------------------------------------------------
PrintStream out;
DateFormat fmt = new SimpleDateFormat();
-
+
Log log = new Log("Viewer logging");
-
+
DefaultTableModel tableModel;
-
+
String source;
String sourceList;
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public ViewerLogging()
{
}
-
+
public ViewerLogging(String source)
{
this.source = source;
-
+
sourceList = ","+source+",";
}
-
+
// Public --------------------------------------------------------
public void initGui()
{
@@ -61,17 +62,17 @@
columnModel.getColumn(0).setMaxWidth(150);
columnModel.getColumn(1).setMaxWidth(100);
JScrollPane sp = new JScrollPane(events);
-
+
frame.getContentPane().add(sp, BorderLayout.CENTER);
-
+
if (source != null)
frame.getContentPane().add(new JLabel("Source filter:"+source),
BorderLayout.NORTH);
-
+
frame.resize(500,500);
frame.show();
}
-
-
+
+
// NotificationListener implementation ---------------------------
public void handleNotification(Notification n,
java.lang.Object handback)
@@ -81,35 +82,35 @@
if (sourceList != null)
if (sourceList.indexOf(n.getUserData().toString()) == -1)
return;
-
-// tableModel.addRow(new Object[] { fmt.format(n.getTimeStamp()),
n.getUserData(), n.getMessage() });
+
+ tableModel.addRow(new Object[] { fmt.format(new Date(n.getTimeStamp())),
n.getUserData(), n.getMessage() });
} catch (Throwable e)
{
Logger.exception(e);
}
}
-
+
// MBeanRegistration implementation ------------------------------
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws java.lang.Exception
{
- // initGui();
-
+ initGui();
+
log.log("Logging started");
-
+
server.addNotificationListener(new
ObjectName(server.getDefaultDomain(),"service","Log"),this,null,null);
-
+
return new ObjectName("DefaultDomain:service=Logging,type=Viewer");
}
-
- public void postRegister(java.lang.Boolean registrationDone)
+
+ public void postRegister(java.lang.Boolean registrationDone)
{
}
-
+
public void preDeregister()
- throws java.lang.Exception
+ throws java.lang.Exception
{}
-
+
public void postDeregister() {}
}