diff -r --unified jabber-1.4.2-orig/jabberd/jabberd.c jabber-1.4.2/jabberd/jabberd.c
--- jabber-1.4.2-orig/jabberd/jabberd.c	2002-02-08 07:39:27.000000000 +0000
+++ jabber-1.4.2/jabberd/jabberd.c	2003-01-13 21:58:21.000000000 +0000
@@ -58,6 +58,7 @@
 pool jabberd__runtime = NULL;
 static char *cfgfile = NULL;
 int jabberd__signalflag = 0;
+FILE *g_logFile = NULL;       /* Log messages here. */
 
 /*** internal functions ***/
 int configurate(char *file);
@@ -100,7 +101,34 @@
         for(c=argv[i]+1;c[0]!='\0';c++)
         {
             /* loop through the characters, like -Dc */
-            if(*c == 'D')
+            if(*c == 'L')
+            {
+		/*
+		 * Default to logging the messages into /var/log/jabber.log,
+		 * but allow the environmental variable to override this.
+		 */
+		char *logfile[ 1024 ];
+		memset( logfile, '\0', sizeof(logfile) );
+		snprintf( logfile, sizeof(logfile)-1,
+			 "/var/log/jabber-%d-%d-%d.log",
+			 getDayNumber(), getMonthNumber(), getYearNumber() );
+
+		/* Open */
+                g_logFile = fopen( logfile, "a" );
+		if (NULL == g_logFile )
+		{
+		    fprintf( stderr, "Failed to open the logfile: %s\n",
+			     logfile );
+		    exit(0);
+		}
+		else
+		{
+		    printf(" Logging chat conversations to '%s'\n",
+			   logfile );
+		}
+                continue;
+            }
+            else if(*c == 'D')
             {
                 do_debug = 1;
                 continue;
@@ -158,7 +186,7 @@
     /* were there any bad parameters? */
     if(help)
     {
-        fprintf(stderr,"Usage:\n%s [params]\n Optional Parameters:\n -c\t\tconfiguration file\n -D\t\tenable debug output (disables background)\n -H\t\tlocation of home folder\n -B\t\tbackground the server process\n -Z\t\tdebug zones\n -v\t\tserver version\n -V\t\tserver version\n", argv[0]);
+        fprintf(stderr,"Usage:\n%s [params]\n Optional Parameters:\n -c\t\tconfiguration file\n -D\t\tenable debug output (disables background)\n -H\t\tlocation of home folder\n -B\t\tbackground the server process\n -Z\t\tdebug zones\n -v\t\tserver version\n -V\t\tserver version\n -L\t\tLog to $FILENAME (/var/log/jabber.log by default\n", argv[0]);
         exit(0);
     }
 
@@ -344,3 +372,45 @@
     }
     _jabberd_shutdown();
 }
+
+/* Get the current month [01-12]. */
+int getMonthNumber()
+{
+    time_t now;
+    char stamp[100];
+    memset( stamp, '\0', sizeof( stamp ) );
+
+    now = time( NULL );
+    strftime( stamp, sizeof( stamp ) -1, "%m", 
+	      localtime( &now ) );
+
+    return( atoi( stamp ) );
+}
+
+/* Get the current day [01-31]. */
+int getDayNumber()
+{
+    time_t now;
+    char stamp[100];
+    memset( stamp, '\0', sizeof( stamp ) );
+
+    now = time( NULL );
+    strftime( stamp, sizeof( stamp ) -1, "%d",
+	      localtime( &now ) );
+
+    return( atoi( stamp ) );
+}
+
+/* Get the current year [00-99]. */
+int getYearNumber()
+{
+    time_t now;
+    char stamp[100];
+    memset( stamp, '\0', sizeof( stamp ) );
+
+    now = time( NULL );
+    strftime( stamp, sizeof( stamp ) -1, "%y", 
+	      localtime( &now ) );
+
+    return( atoi( stamp ) );
+}
diff -r --unified jabber-1.4.2-orig/jabberd/jabberd.h jabber-1.4.2/jabberd/jabberd.h
--- jabber-1.4.2-orig/jabberd/jabberd.h	2002-02-08 07:39:27.000000000 +0000
+++ jabber-1.4.2/jabberd/jabberd.h	2003-01-13 21:58:21.000000000 +0000
@@ -44,6 +44,7 @@
 #include <ssl.h>
 #endif /* HAVE_SSL */
 
+#include <stdio.h>  /* For FILE */
 #define VERSION "1.4.2"
 
 /* packet types */
@@ -352,3 +353,15 @@
 /* some nice api utilities */
 #define mio_pool(m) (m->p)
 #define mio_ip(m) (m->ip)
+
+/* The file to log messages to. */
+extern FILE *g_logFile;
+
+/* Get the current month [01-12]. */
+extern int getMonthNumber();
+
+/* Get the current day [01-31]. */
+extern int getDayNumber();
+
+/* Get the current year [00-99]. */
+extern int getYearNumber();
--- jabber-1.4.2-orig/jabberd/mio.c	2002-02-08 07:39:27.000000000 +0000
+++ jabber-1.4.2/jabberd/mio.c	2003-01-13 21:58:21.000000000 +0000
@@ -243,6 +243,25 @@
         m->next->prev = m->prev;
 }
 
+
+/*
+ *  Get todays date and time in a format suitable for logging.
+ *
+ *  Memory must not be free'd.
+ */
+char * _mio_get_date_time( )
+{
+    time_t now;
+    char stamp[100];
+    memset( stamp, '\0', sizeof( stamp ) );
+
+    now = time( NULL );
+    strftime( stamp, sizeof( stamp ) -1, "[ %d/%b/%G:%H:%M:%S ] ", 
+	      localtime( &now ) );
+
+    return( stamp );
+}
+
 /* 
  * links a socket to the master list 
  */
@@ -271,13 +290,153 @@
     int len;
     mio_wbq cur;
 
+    static int day   = -1;
+    static int month = -1;
+    static int year  = -1;
+
+    int newDay   = getDayNumber();
+    int newMonth = getMonthNumber();
+    int newYear  = getYearNumber();
+
+    if ( ( newDay != day ) ||
+	 ( newMonth != month ) ||
+	 ( newYear != year ) )
+    {
+      /* First time initialization. */
+      if ( day != -1 )
+      {
+	char *logfile[ 1024 ];
+	fflush( g_logFile );
+	fclose( g_logFile );
+	
+	/*
+	 * Default to logging the messages into /var/log/jabber.log,
+	 * but allow the environmental variable to override this.
+	 */
+	memset( logfile, '\0', sizeof(logfile) );
+	snprintf( logfile, sizeof(logfile)-1,
+		 "/var/log/jabber-%d-%d-%d.log",
+		 getDayNumber(), getMonthNumber(), getYearNumber() );
+	
+	/* Open */
+	g_logFile = fopen( logfile, "a" );
+	if (NULL == g_logFile )
+	  {
+	    fprintf( stderr, "Failed to open the logfile: %s\n",
+		     logfile );
+	    exit(0);
+	  }
+
+	day   = newDay;
+	month = newMonth;
+	year  = newYear;
+      }
+    }
+
     /* try to write as much as we can */
     while(m->queue != NULL)
     {
+        char *from = NULL;
+        char *to   = NULL;
+        char *body = NULL;
+        char *bend = NULL;
+      
+	char *tmp  = NULL;
         cur = m->queue;
 
+#if 0
+
+	/*
+	 * Example of the kind of message we log:
+	 */
+Sep 23 20:22:17 2002  mio.c:279 write_dump writing data: <message type='chat' to='steve@hell' from='test@hell/Psi'><body>ss</body></message>
+
+#endif
+
         log_debug(ZONE, "write_dump writing data: %.*s", cur->len, cur->cur);
 
+	/* Copy message to a temporary file. */
+	tmp = (char *)malloc( cur->len + 1 );
+	memset( tmp, cur->len+1, '\0' );
+	strcpy( tmp, cur->cur );
+
+	from = strstr( tmp, "from=\"" );
+	if ( from == NULL )
+	{
+	  from = strstr( tmp, "from='" );
+	}
+
+	to = strstr( tmp, "to=\"" );
+	if ( to == NULL )
+	{
+	  to = strstr( tmp, "to='" );
+	}
+
+	body = strstr( tmp, "<body>" );
+	bend = strstr( tmp, "</body>" );
+
+	/*
+	 * Only log if we have all the information.
+	 */
+	if ( ( from != NULL ) &&
+	     ( to   != NULL ) &&
+	     ( body != NULL ) &&
+	     ( bend != NULL ) )
+        {
+	  char *fend;
+	  char *tend;
+	  int found  = 0;
+
+	  from += strlen( "from=?" );
+	  to   += strlen( "to=?" );
+
+	  fend = from;
+	  tend = to;
+
+	  while( !found )
+	  {
+	    if ( ( fend[0] == '\"' ) || ( fend[0] == '\'' ) )
+	      {
+		fend[0] = '\0';
+		found = 1;
+	      }
+	    fend++;
+	  }
+
+
+	  found = 0;
+	  while( !found )
+	  {
+	    if ( ( tend[0] == '\"' ) || ( tend[0] == '\'' ) )
+	      {
+		tend[0] = '\0';
+		found = 1;
+	      }
+	    tend++;
+	  }
+	  
+	  body += strlen( "<body>" );
+	  bend[ 0 ] = '\0';
+
+	  if (NULL != g_logFile )
+	  {
+	    /*
+	     * Write the date + time + message to the logfile.
+	     */
+	    fprintf( g_logFile, "%s FROM: %s TO: %s  -> MSG: %s\n",
+		     _mio_get_date_time(), from, to, body );
+	    fflush( g_logFile );
+	  }
+#if 0
+	  printf( "FROM: %s\n", from );
+	  printf( "  TO: %s\n", to );
+	  printf( "BODY: %s\n", body );
+#endif 
+	}
+
+	/* Clean up memory. */
+	free( tmp );
+
         /* write a bit from the current buffer */
         len = (*m->mh->write)(m, cur->cur, cur->len);
         /* we had an error on the write */
