|
|
|
How to write a MODULE_LOGGER ?
Name
How to write a MODULE_LOGGER that write a sample httpd log file with the following format : host.user.net http://www.referer.net/mail/ - [18/Feb/2004:18:22:24 +0100] "GET / HTTP/1.1" 200 1003 host.user.net - - [18/Feb/2004:18:22:25 +0100] "GET /favicon.ico HTTP/1.1" 404 682 Caudium 1.0, 1.2, 1.3 The following module allows you to define your own logger module. It can help you to make your own version of it and replace the default logging system. #include <module.h> inherit "module"; inherit "caudiumlib"; constant module_type = MODULE_LOGGER; constant module_name = "Sample Logger module"; constant module_doc = "Sample Logger module to show how Logging system" " in Caudium."; void create() { defvar("logfile","/var/log/httpd/httpd.log","Log file", TYPE_STRING, "This is the file where is logged all clients accesses.\n"); } // Used to have the opened file access when logging for speed object logf; void start() { object c=Stdio.File(); logf=0; // Reset the old value, if any.. if(!(c->open(QUERY(logfile), "wca"))) report_error("Clientlogger: Cannot open logfile.\n"); else logf = c; } void stop() { logf->close(); } /* * function log, * * This function log the access from client according to his request id * */ void log(object id, mapping file) { logf->write(caudium->quick_ip_to_host(id->remoteaddr) + " " + (sizeof(id->referer)?id->referer[0]:"-") + " - ["+ cern_http_date(id->time) + "] \"" + id->method + " " + id->raw_url + " " + id->clientprot + "\" " + (file->error||200) + " " + file->len +"\n"); } |
|
Copyright © 2000 - 2005
The Caudium Group
All Rights Reserved. Hosting by Kazar.
|
|