backported new logvars from 1.5

This commit is contained in:
Unbit
2013-01-28 22:44:54 +01:00
parent 719860a349
commit 02d76f12e0
3 changed files with 89 additions and 2 deletions
+75 -2
View File
@@ -815,10 +815,11 @@ struct uwsgi_logger *uwsgi_get_logger_from_id(char *id) {
void uwsgi_logit_lf(struct wsgi_request *wsgi_req) {
struct uwsgi_logchunk *logchunk = uwsgi.logchunks;
ssize_t rlen = 0;
const char *empty_var = "-";
while (logchunk) {
int pos = logchunk->vec;
// raw string
if (logchunk->type == 0) {
if (logchunk->type == 0 && logchunk->type != 0) {
uwsgi.logvectors[wsgi_req->async_id][pos].iov_base = logchunk->ptr;
uwsgi.logvectors[wsgi_req->async_id][pos].iov_len = logchunk->len;
}
@@ -851,6 +852,11 @@ void uwsgi_logit_lf(struct wsgi_request *wsgi_req) {
uwsgi.logvectors[wsgi_req->async_id][pos].iov_len = 0;
}
}
if (uwsgi.logvectors[wsgi_req->async_id][pos].iov_len == 0) {
uwsgi.logvectors[wsgi_req->async_id][pos].iov_base = (char *) empty_var;
uwsgi.logvectors[wsgi_req->async_id][pos].iov_len = 1;
}
logchunk = logchunk->next;
}
@@ -862,7 +868,9 @@ void uwsgi_logit_lf(struct wsgi_request *wsgi_req) {
while (logchunk) {
if (logchunk->free) {
if (uwsgi.logvectors[wsgi_req->async_id][logchunk->vec].iov_len > 0) {
free(uwsgi.logvectors[wsgi_req->async_id][logchunk->vec].iov_base);
if (uwsgi.logvectors[wsgi_req->async_id][logchunk->vec].iov_base != empty_var) {
free(uwsgi.logvectors[wsgi_req->async_id][logchunk->vec].iov_base);
}
}
}
logchunk = logchunk->next;
@@ -928,6 +936,27 @@ ssize_t uwsgi_lf_status(struct wsgi_request *wsgi_req, char **buf) {
return strlen(*buf);
}
ssize_t uwsgi_lf_rsize(struct wsgi_request *wsgi_req, char **buf) {
*buf = uwsgi_num2str(wsgi_req->response_size);
return strlen(*buf);
}
ssize_t uwsgi_lf_hsize(struct wsgi_request *wsgi_req, char **buf) {
*buf = uwsgi_num2str(wsgi_req->headers_size);
return strlen(*buf);
}
ssize_t uwsgi_lf_size(struct wsgi_request *wsgi_req, char **buf) {
*buf = uwsgi_num2str(wsgi_req->headers_size+wsgi_req->response_size);
return strlen(*buf);
}
ssize_t uwsgi_lf_cl(struct wsgi_request *wsgi_req, char **buf) {
*buf = uwsgi_num2str(wsgi_req->post_cl);
return strlen(*buf);
}
ssize_t uwsgi_lf_epoch(struct wsgi_request * wsgi_req, char **buf) {
*buf = uwsgi_num2str(uwsgi_now());
return strlen(*buf);
@@ -948,6 +977,17 @@ ssize_t uwsgi_lf_time(struct wsgi_request * wsgi_req, char **buf) {
return strlen(*buf);
}
ssize_t uwsgi_lf_ltime(struct wsgi_request * wsgi_req, char **buf) {
*buf = uwsgi_malloc(64);
time_t now = wsgi_req->start_of_request / 1000000;
size_t ret = strftime(*buf, 64, "%d/%b/%Y:%H:%M:%S %z", localtime(&now));
if (ret == 0) {
*buf[0] = 0;
return 0;
}
return ret;
}
ssize_t uwsgi_lf_micros(struct wsgi_request * wsgi_req, char **buf) {
@@ -1018,11 +1058,39 @@ void uwsgi_add_logchunk(int variable, int pos, char *ptr, size_t len) {
logchunk->pos = offsetof(struct wsgi_request, protocol);
logchunk->pos_len = offsetof(struct wsgi_request, protocol_len);
}
else if (!uwsgi_strncmp(ptr, len, "uagent", 6)) {
logchunk->pos = offsetof(struct wsgi_request, user_agent);
logchunk->pos_len = offsetof(struct wsgi_request, user_agent_len);
}
else if (!uwsgi_strncmp(ptr, len, "referer", 7)) {
logchunk->pos = offsetof(struct wsgi_request, referer);
logchunk->pos_len = offsetof(struct wsgi_request, referer_len);
}
else if (!uwsgi_strncmp(ptr, len, "status", 6)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_status;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "rsize", 5)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_rsize;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "hsize", 5)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_hsize;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "size", 4)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_size;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "cl", 2)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_cl;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "micros", 6)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_micros;
@@ -1038,6 +1106,11 @@ void uwsgi_add_logchunk(int variable, int pos, char *ptr, size_t len) {
logchunk->func = uwsgi_lf_time;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "ltime", 5)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_ltime;
logchunk->free = 1;
}
else if (!uwsgi_strncmp(ptr, len, "ctime", 5)) {
logchunk->type = 3;
logchunk->func = uwsgi_lf_ctime;
+8
View File
@@ -883,6 +883,14 @@ int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
wsgi_req->authorization = ptrbuf;
wsgi_req->authorization_len = strsize;
}
else if (!uwsgi_strncmp("HTTP_USER_AGENT", 15, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->user_agent = ptrbuf;
wsgi_req->user_agent_len = strsize;
}
else if (!uwsgi_strncmp("HTTP_REFERER", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->referer = ptrbuf;
wsgi_req->referer_len = strsize;
}
else if (!uwsgi_strncmp("DOCUMENT_ROOT", 13, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->document_root = ptrbuf;
wsgi_req->document_root_len = strsize;
+6
View File
@@ -1014,6 +1014,12 @@ struct wsgi_request {
char *authorization;
uint16_t authorization_len;
char *user_agent;
uint16_t user_agent_len;
char *referer;
uint16_t referer_len;
char *script;
uint16_t script_len;
char *module;