Mailing List Archive

anyone already extracting the log-information from syslog?
Hi folks,

does anyone already have a sed/awk/perl or similar script to
extract the cherokee-log information from the syslog-files?
I want to run the usual logfile-analyzer over it, but I'm
pretty sure it'll not work on the syslog-files ;-).

As far as I see, the loginformation is currently mostly standard
and could be analyzed without further hazzle (once its extracted ;-)).


TIA,

Thomas
anyone already extracting the log-information from syslog? [ In reply to ]
Hi Thomas,

I just patched cherokee 0.43 to redirect every connection log message to
/var/log/cherokee/access.log, the format is similar to the access.log
file of apache (NCSA combined/extended format)whether it's not fully
implemented yet (as you can see, the size of the object request is
always zero and this is wrong), so you can run any kind of log-analyzer
over it. I think this is smarter than using any script.

Anyhow I also found a bug in the cherokee_connection_log() function, the
IP showed is wrong, you can try by connecting from localhost (I got an
horrible IP, something like 2.0.128.32), so I also fixed this.

To get cherokee running with my patch:

1) download and untar cherokee-0.43.tar.gz
2) mv patch.diff /usr/src/cherokee-0.43/
3) cd /usr/src/cherokee-0.43/
4) patch -p1 < patch.diff
5) ./configure && make && make install
6) mkdir /var/log/cherokee/
7) chown cherokee.cherokee(well, not exactly, have a look at
cherokee.conf to see the owner of the cherokee process, the settings
User and Group).
8) Run cherokee.

I think I didn't forget anything. If anyproblem, let me know.

Cheers,
Pablo

P.S: I also sent this patch to Alo, the author.

-------------- next part --------------
diff -uNr cherokee-0.4.3/src/connection.c cherokee-0.4.3-07062003/src/connection.c
--- cherokee-0.4.3/src/connection.c 2003-05-09 17:56:16.000000000 +0200
+++ cherokee-0.4.3-07062003/src/connection.c 2003-06-07 17:26:16.000000000 +0200
@@ -69,7 +69,7 @@
n->timeout = time(NULL) + 15;
n->range_start = 0;
n->range_end = 0;
-
+
cherokee_buffer_new (&n->local_directory);
cherokee_buffer_new (&n->web_directory);
cherokee_buffer_new (&n->request);
@@ -726,11 +726,12 @@


void
-cherokee_connection_log (cherokee_connection_t *cnt, time_t bogo_now)
+cherokee_connection_log (cherokee_connection_t *cnt, time_t bogo_now, FILE *fd)
{
struct tm *timep;
long int z;
-
+ struct sockaddr_in *addr;
+
timep = (struct tm *) localtime(&bogo_now);

#ifdef HAVE_INT_TIMEZONE
@@ -741,7 +742,7 @@
#endif


- snprintf (gbl_buffer, gbl_buffer_size, "%s - - [%02d/%s/%d:%02d:%02d:%02d %c%02d%02d] \"%s %s %s\" %d %ld",
+ snprintf (gbl_buffer, gbl_buffer_size, "%s - - [%02d/%s/%d:%02d:%02d:%02d %c%02d%02d] \"%s %s %s\" %d %ld\n",
inet_ntoa(cnt->addr_in),
timep->tm_mday,
month[timep->tm_mon],
@@ -758,5 +759,6 @@
cnt->error_code,
cnt->range_end - cnt->range_start);

+ cherokee_accesslog (fd, gbl_buffer);
cherokee_log (LOG_INFO, gbl_buffer);
}
diff -uNr cherokee-0.4.3/src/connection.h cherokee-0.4.3-07062003/src/connection.h
--- cherokee-0.4.3/src/connection.h 2003-05-11 11:47:17.000000000 +0200
+++ cherokee-0.4.3-07062003/src/connection.h 2003-06-07 17:24:28.000000000 +0200
@@ -34,6 +34,7 @@

#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>

#include "list.h"
#include "http.h"
@@ -66,7 +67,7 @@
void *server;

int socket;
- struct sockaddr addr_in;
+ struct in_addr addr_in;

cherokee_connection_status_t status;
cherokee_connection_phase_t phase;
@@ -105,7 +106,7 @@
ret_t cherokee_connection_clean (cherokee_connection_t *cnt);
ret_t cherokee_connection_mrproper (cherokee_connection_t *cnt);
ret_t cherokee_connection_set_socket (cherokee_connection_t *cnt, int socket);
-void cherokee_connection_log (cherokee_connection_t *cnt, time_t bogo_now);
+void cherokee_connection_log (cherokee_connection_t *cnt, time_t bogo_now, FILE *fd);

/* Send & Recv
*/
diff -uNr cherokee-0.4.3/src/log.c cherokee-0.4.3-07062003/src/log.c
--- cherokee-0.4.3/src/log.c 2003-04-20 13:06:52.000000000 +0200
+++ cherokee-0.4.3-07062003/src/log.c 2003-06-07 17:24:28.000000000 +0200
@@ -29,11 +29,47 @@

static int __cherokee_logging = 0;

+FILE*
+cherokee_accesslog_init(void)
+{
+ FILE *fd;
+
+ fd = fopen("/var/log/cherokee/access.log", "w+");
+ if (fd == NULL)
+ return(NULL);
+
+ return(fd);
+}
+
+ret_t
+cherokee_accesslog_close(FILE *fd)
+{
+ if (fclose(fd) == 0)
+ return(ret_ok);
+ else
+ return(ret_error);
+}
+
+ret_t
+cherokee_accesslog(FILE *fd, char *log)
+{
+ if (fd == NULL)
+ return(ret_error);
+
+ if (fputs(log, fd) > 0) {
+ fflush(fd);
+ return(ret_ok);
+ }
+
+ return(ret_error);
+}
+
ret_t
cherokee_log_init (void)
{
openlog (PACKAGE, LOG_PID, LOG_DAEMON);
__cherokee_logging = 1;
+
return ret_ok;
}

diff -uNr cherokee-0.4.3/src/log.h cherokee-0.4.3-07062003/src/log.h
--- cherokee-0.4.3/src/log.h 2003-04-17 14:46:31.000000000 +0200
+++ cherokee-0.4.3-07062003/src/log.h 2003-06-07 17:24:28.000000000 +0200
@@ -31,6 +31,9 @@
#include <syslog.h>


+FILE* cherokee_accesslog_init(void);
+ret_t cherokee_accesslog_close(FILE *);
+ret_t cherokee_accesslog(FILE *, char *);
ret_t cherokee_log_init (void);
ret_t cherokee_log_close (void);
void cherokee_log (int priority, const char *format, ...);
diff -uNr cherokee-0.4.3/src/server.c cherokee-0.4.3-07062003/src/server.c
--- cherokee-0.4.3/src/server.c 2003-05-10 13:08:56.000000000 +0200
+++ cherokee-0.4.3-07062003/src/server.c 2003-06-07 17:24:28.000000000 +0200
@@ -105,7 +105,11 @@

cherokee_virtual_server_new (&n->vserver_default);
return_if_fail (n->vserver_default!=NULL, ret_nomem);
-
+
+ /* Access log
+ */
+
+ n->accesslog = NULL;

/* Return the object
*/
@@ -388,6 +392,13 @@
srv->log = active;
ret = cherokee_log_init();
cherokee_log (LOG_NOTICE, "Starting log");
+
+ srv->accesslog = cherokee_accesslog_init();
+ if (srv->accesslog == NULL)
+ cherokee_log (LOG_NOTICE, "Error starting access log");
+ else
+ cherokee_log (LOG_NOTICE, "Starting access log");
+
return ret;
}

@@ -398,6 +409,8 @@
static inline int
look_for_new_connection (cherokee_server_t *srv)
{
+ struct sockaddr_in addr;
+
/* Look for new connections
*/
if (cherokee_fdpoll_check (srv->fdpoll, srv->socket, 0))
@@ -425,7 +438,8 @@
if (srv->log) {
socklen_t len;
len = sizeof(struct sockaddr_in);
- new_socket = accept (srv->socket, &new_connection->addr_in, &len);
+ new_socket = accept (srv->socket, (struct sockaddr *)&addr, &len);
+ memcpy(&new_connection->addr_in, &addr.sin_addr, sizeof(struct in_addr));
} else {
new_socket = accept (srv->socket, NULL, NULL);
}
@@ -591,7 +605,7 @@
/* Maybe log it
*/
if (srv->log) {
- cherokee_connection_log (conn, srv->bogo_now);
+ cherokee_connection_log (conn, srv->bogo_now, srv->accesslog);
}


diff -uNr cherokee-0.4.3/src/server.h cherokee-0.4.3-07062003/src/server.h
--- cherokee-0.4.3/src/server.h 2003-05-05 10:34:27.000000000 +0200
+++ cherokee-0.4.3-07062003/src/server.h 2003-06-07 17:24:28.000000000 +0200
@@ -71,7 +71,9 @@
char *mimetypes_file;

char *userdir; /* Eg: public_html */
- cherokee_plugin_table_entry_t *userdir_handler;
+ cherokee_plugin_table_entry_t *userdir_handler;
+
+ FILE *accesslog;
} cherokee_server_t;