I created the attached patches to allow for charset translation on the 
SyslogAppender.  When using log4j on a S390 system it will send all the 
datagrams in EBCDIC, instead of ASCII.  With the patch you can add an 
optional charset for example:

 log4j.appender.UnixSyslog.SyslogHost=myhost/US-ASCII

I was not sure if it was acceptable to share a property like this.  I started 
to make a charset property but it turned out to be more efficient to share 
SyslogHost, mostly due to the order objects seemed to be created.

Could this patch be added to a future release?

Thanks.

Jay van der Meer
--- org-SyslogAppender.java	2003-07-09 17:01:30.000000000 -0500
+++ SyslogAppender.java	2003-07-09 17:03:53.000000000 -0500
@@ -84,6 +84,7 @@
   //SyslogTracerPrintWriter stp;
   SyslogQuietWriter sqw;
   String syslogHost;
+  String CharSet = null;
 
   public
   SyslogAppender() {
@@ -285,12 +286,25 @@
    */
   public
   void setSyslogHost(String syslogHost) {
-    this.sqw = new SyslogQuietWriter(new SyslogWriter(syslogHost),
+    int chrsetpos;
+    String WorkHost = null;
+    
+    chrsetpos = syslogHost.indexOf("/");
+    
+    if (chrsetpos != -1) {
+      WorkHost = syslogHost.substring(0,chrsetpos);
+      this.CharSet = syslogHost.substring(chrsetpos+1);
+    }
+    else
+      WorkHost = syslogHost;
+    
+    this.sqw = new SyslogQuietWriter(new SyslogWriter(WorkHost,CharSet),
 				     syslogFacility, errorHandler);
     //this.stp = new SyslogTracerPrintWriter(sqw);
-    this.syslogHost = syslogHost;
+    this.syslogHost = WorkHost;
   }
 
+
   /**
      Returns the value of the <b>SyslogHost</b> option.
    */
@@ -299,6 +313,7 @@
     return syslogHost;
   }
 
+
   /**
      Set the syslog facility. This is the <b>Facility</b> option.
 
--- org-SyslogWriter.java	2003-07-09 17:01:36.000000000 -0500
+++ SyslogWriter.java	2003-07-09 17:03:58.000000000 -0500
@@ -27,13 +27,15 @@
 
   final int SYSLOG_PORT = 514;
   static String syslogHost;
+  static String CharSet = null;
   
   private InetAddress address;
   private DatagramSocket ds;
 
   public
-  SyslogWriter(String syslogHost) {
+  SyslogWriter(String syslogHost, String TheCharSet) {
     this.syslogHost = syslogHost;
+    this.CharSet = TheCharSet;
 
     try {      
       this.address = InetAddress.getByName(syslogHost);
@@ -61,7 +63,13 @@
   
   public
   void write(String string) throws IOException {
-    byte[] bytes = string.getBytes();
+  byte[] bytes = null;
+    
+    if (CharSet != null)
+      bytes = string.getBytes(CharSet);
+    else
+      bytes = string.getBytes();
+      
     DatagramPacket packet = new DatagramPacket(bytes, bytes.length,
 					       address, SYSLOG_PORT);
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to