Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: users

logging support

 

 

Cherokee users RSS feed   Index | Next | Previous | View Threaded


pablo at eurodev

Jun 26, 2003, 12:36 AM

Post #1 of 4 (283 views)
Permalink
logging support

Hi everyone!

I just programmed a first try of the logging modules, it's called the
NCSA logging module and the other ones, like the implementation of the
CLF format, would have the same structure, let me show you how I did it.

I added four new fields to the cherokee_server_t structure, they are:

char *accesslog_file; /* access log file path, in example:
/var/www/cherokee/access.log */
char *errorlog_file; /* error log file path */
FILE *accesslog_fd; /* File descriptor for access.log file */
FILE *errorlog_fd; /* File descriptor for error.log file */

a couple of files called logging_NCSA.c and logging_NCSA.h. They
cointain the implementation of following functions:

ret_t cherokee_logging_NCSA_open (cherokee_server_t *srv);
ret_t cherokee_logging_NCSA_write (cherokee_connection_t *cnt);
ret_t cherokee_logging_NCSA_close (cherokee_server_t *srv);

the first one is to open the log file. When cherokee is starting, it
does the following steps:

a) read the name of the logging module (only NCSA format available at
this moment, and not fully implemented) which will be use to log,
afterwards we got the path where the access.log file is. Like handlers,
we'll use a pointer to a function depending on what logging module we
set in the config file, so instead of using those names to call open,
close and write, we could use something like:

ret_t (*cherokee_logging_open) (cherokee_server_t *srv);
ret_t (*cherokee_logging_write) (cherokee_connection_t *cnt);
ret_t (*cherokee_logging_close) (cherokee_server_t *srv);

and we could add this to a structure in log.h (well, you know, like
handler works). is it ok?

status of this issue: I know something of bison, so I think I could add
this new fields to the config file with not so many problems. I can
create a brand new type called cherokee_logging_open_t,
cherokee_logging_close_t and cherokee_logging_write_t, the new structure
called cherokee_logging_t with fields with those brand new types and so
on (if you don't know what I'm talking about, have a look at handler.h).

b) I need to add the new files to the Makefile and I don't know anything
about the autoshit (autoconf) stuff. I made sure that those new filed
compiled (gcc -c logging_NCSA.c -o foo) with no problems but I could not
test if they work because of this matter, could anyone help me out? and
any docs I could read to understand this stuff (autoshit) better? could
you show me a simple step by step of how to add new files to cherokee...

status of this issue: stand by.

hey! that's all! bye bye indians
let me know what you think about my work. I'm also working on
multithread and ssl support, just reading stuff and thinking how to do
it as nice as possible.

Pablo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logging_NCSA.c
Type: text/x-csrc
Size: 2490 bytes
Desc: not available
Url : /pipermail/attachments/20030626/226b4a12/logging_NCSA.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logging_NCSA.h
Type: text/x-chdr
Size: 1587 bytes
Desc: not available
Url : /pipermail/attachments/20030626/226b4a12/logging_NCSA-0001.bin
-------------- next part --------------
? logging_NCSA.c
? logging_NCSA.h
? patch.diff
Index: Makefile.am
===================================================================
RCS file: /cherokee/cherokee/src/Makefile.am,v
retrieving revision 1.2
diff -u -w -r1.2 Makefile.am
Index: connection.c
===================================================================
RCS file: /cherokee/cherokee/src/connection.c,v
retrieving revision 1.8
diff -u -w -r1.8 connection.c
--- connection.c 18 Jun 2003 19:42:58 -0000 1.8
+++ connection.c 25 Jun 2003 21:43:07 -0000
@@ -31,12 +31,6 @@
#include <pwd.h>
#include <time.h>

-/* inet_ntoa()
- */
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
#include "log.h"
#include "handler.h"
#include "handler_dirlist.h"
@@ -47,15 +41,6 @@
#include "encoder_table.h"


-static char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
-
-static char *method[] = {"GET", "POST", "HEAD", "UNKNOWN", NULL};
-
-static char *version[] = {"HTTP/0.9", "HTTP/1.0", "HTTP/1.1", "UNKNOWN", NULL};
-
-
-
ret_t
cherokee_connection_new (cherokee_connection_t **cnt)
{
@@ -872,41 +857,3 @@
return ret_error;
}

-
-
-void
-cherokee_connection_log (cherokee_connection_t *cnt, time_t bogo_now)
-{
- struct tm *timep;
- long int z;
-
- timep = (struct tm *) localtime(&bogo_now);
-
-#ifdef HAVE_INT_TIMEZONE
- z = - (timezone / 60);
-#else
-#warning TODO
- z = 0;
-#endif
-
- snprintf (gbl_buffer, gbl_buffer_size, "%s - - [%02d/%s/%d:%02d:%02d:%02d %c%02d%02d] \"%s %s %s\" %d %d",
-
- inet_ntoa(cnt->addr_in.sin_addr),
-
- timep->tm_mday,
- month[timep->tm_mon],
- 1900 + timep->tm_year,
- timep->tm_hour,
- timep->tm_min,
- timep->tm_sec,
- (z < 0) ? '-' : '+',
- (int) z/60,
- (int) z%60,
- method[cnt->method],
- cnt->request->buf,
- version[cnt->version],
- cnt->error_code,
- cnt->range_end - cnt->range_start);
-
- cherokee_log (LOG_INFO, gbl_buffer);
-}
Index: connection.h
===================================================================
RCS file: /cherokee/cherokee/src/connection.h,v
retrieving revision 1.3
diff -u -w -r1.3 connection.h
--- connection.h 17 Jun 2003 11:11:07 -0000 1.3
+++ connection.h 25 Jun 2003 21:43:07 -0000
@@ -69,7 +69,8 @@
void *server;

int socket;
- struct sockaddr_in addr_in;
+ struct sockaddr_in addr;
+

cherokee_connection_status_t status;
cherokee_connection_phase_t phase;
Index: server.c
===================================================================
RCS file: /cherokee/cherokee/src/server.c,v
retrieving revision 1.4
diff -u -w -r1.4 server.c
--- server.c 18 Jun 2003 19:42:58 -0000 1.4
+++ server.c 25 Jun 2003 21:43:10 -0000
@@ -87,6 +87,9 @@
n->group_orig = getgid();
n->group = n->group_orig;

+ n->accesslog_file = NULL;
+ n->errorlog_file = NULL;
+ n->log_fd = NULL;

/* Virtual servers table
*/
@@ -423,7 +426,7 @@
if (srv->log) {
socklen_t len;
len = sizeof(struct sockaddr_in);
- new_socket = accept (srv->socket, (struct sockaddr *) &new_connection->addr_in, &len);
+ new_socket = accept (srv->socket, (struct sockaddr_in *)&new_connection->addr, &len);
} else {
new_socket = accept (srv->socket, NULL, NULL);
}
Index: server.h
===================================================================
RCS file: /cherokee/cherokee/src/server.h,v
retrieving revision 1.1
diff -u -w -r1.1 server.h
--- server.h 3 Jun 2003 15:14:37 -0000 1.1
+++ server.h 25 Jun 2003 21:43:11 -0000
@@ -73,6 +73,10 @@
gid_t group;
gid_t group_orig;

+ char *accesslog_file;
+ char *errorlog_file;
+ FILE *log_fd;
+
char *mimetypes_file;

char *userdir; /* Eg: public_html */


ajo at godsmaze

Jun 26, 2003, 3:57 AM

Post #2 of 4 (279 views)
Permalink
logging support [In reply to]

Hello pablo,

Thursday, June 26, 2003, 1:29:32 AM, you wrote:

pn> Hi everyone!

pn> char *accesslog_file; /* access log file path, in example:
pn> /var/www/cherokee/access.log */
pn> char *errorlog_file; /* error log file path */
pn> FILE *accesslog_fd; /* File descriptor for access.log file */
pn> FILE *errorlog_fd; /* File descriptor for error.log file */


hi!, nice work, but ...
I think logging support should keep it's filenames and descriptors
outside of the main server structure....

so you can do the thing a little bit more abstract....
just think what you can do if you need to do logger module that logs
every access in a mysql database instead of doing it to a file... :)


may be passing the configuration (filenames or database+tables or
whatever) to the module thru a config function... and keeping all the
related data inside the module... or just a pointer in the cherokee_server_t

something like:

void *logger_module_privatedata;

- the module_config function, when called... creates the structure with:

char *accesslog_file; /* access log file path, in example:
/var/www/cherokee/access.log */
char *errorlog_file; /* error log file path */
FILE *accesslog_fd; /* File descriptor for access.log file */
FILE *errorlog_fd; /* File descriptor for error.log file */

- fills up the data (reading from configfile... or passed by cherokee...
or whatever..)

- and points logger_module_privatedata to it...



It's 4:42 am... I was studying so... may be I got crazy... ;-)

anyway... I'm crazy or not.. it would be much more flexible doing it this way...

what do you think? :-)




--
Best regards,
Miguel Angel mailto:ajo [at] godsmaze


pablo at eurodev

Jun 26, 2003, 10:05 AM

Post #3 of 4 (286 views)
Permalink
logging support [In reply to]

Hi there,

>something like:
>
>void *logger_module_privatedata;
>
>- the module_config function, when called... creates the structure with:
>
>char *accesslog_file; /* access log file path, in example:
>/var/www/cherokee/access.log */
>char *errorlog_file; /* error log file path */
>FILE *accesslog_fd; /* File descriptor for access.log file */
>FILE *errorlog_fd; /* File descriptor for error.log file */
>
it's ok, so something like:

typedef struct cherokee_logging_config_t {
char *accesslog_file;
char *errorlog_file;
FILE *accesslog_fd;
FILE *errorlog_fd;
} cherokee_logging_config_t;

and in cherokee_server_t a new field:

void *logger_module_privatedata;

and functions looks like:

ret_ cherokee_logging_NCSA_open(cherokee_logging_config_t *config);
ret_ cherokee_logging_NCSA_close(cherokee_logging_config_t *config);
ret_ cherokee_logging_NCSA_write(cherokee_connection_t *config); <---
I cannot change the parameter of this one

is it all right?

>
>- fills up the data (reading from configfile... or passed by cherokee...
>or whatever..)
>
>- and points logger_module_privatedata to it...
>
>
>
>It's 4:42 am... I was studying so... may be I got crazy... ;-)
>
it's nice, I don't need to change so many things to add this thing.
Anyway I still need to know how to add new files to cherokee, I know you
all are busy (exams, hey I finished) so I'll be patient (and I'll also
RTFM).

Bye
Pablo


pablo at eurodev

Jun 26, 2003, 11:14 AM

Post #4 of 4 (282 views)
Permalink
logging support [In reply to]

Pablo wrote:

> Hi there,
>
>> something like:
>>
>> void *logger_module_privatedata;
>>
>> - the module_config function, when called... creates the structure with:
>>
>> char *accesslog_file; /* access log file path, in example:
>> /var/www/cherokee/access.log */
>> char *errorlog_file; /* error log file path */
>> FILE *accesslog_fd; /* File descriptor for access.log file */
>> FILE *errorlog_fd; /* File descriptor for error.log file */
>>
> it's ok, so something like:
>
> typedef struct cherokee_logging_config_t {
> char *accesslog_file;
> char *errorlog_file;
> FILE *accesslog_fd;
> FILE *errorlog_fd;
> } cherokee_logging_config_t;
>
> and in cherokee_server_t a new field:
>
> void *logger_module_privatedata;
>
> and functions looks like:
>
> ret_ cherokee_logging_NCSA_open(cherokee_logging_config_t *config);
> ret_ cherokee_logging_NCSA_close(cherokee_logging_config_t *config);
> ret_ cherokee_logging_NCSA_write(cherokee_connection_t *config);
> <--- I cannot change the parameter of this one


sorry, I meant:

ret_ cherokee_logging_NCSA_write(cherokee_connection_t *cnt);

>
>
> is it all right?
>
>>
>> - fills up the data (reading from configfile... or passed by cherokee...
>> or whatever..)
>>
>> - and points logger_module_privatedata to it...
>>
>>
>>
>> It's 4:42 am... I was studying so... may be I got crazy... ;-)
>>
> it's nice, I don't need to change so many things to add this thing.
> Anyway I still need to know how to add new files to cherokee, I know
> you all are busy (exams, hey I finished) so I'll be patient (and I'll
> also RTFM).
>
> Bye
> Pablo
>
>
> _______________________________________________
> Cherokee mailing list
> Cherokee [at] alobbs
> http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
>

Cherokee users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.