<commit_before>/*
 * Access logging.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "access-log.h"

#ifndef NO_ACCESS_LOG

#include "http-server.h"
#include "log-glue.h"

#include <time.h>

void
access_log(struct http_server_request *request, const char *site,
           http_status_t status, off_t content_length,
           uint64_t bytes_received, uint64_t bytes_sent)
{
    if (log_global_enabled()) {
        log_http_request(time(NULL) * 1000000, request->method, request->uri,
                         request->remote_host, site, NULL, NULL,
                         status, content_length,
                         bytes_received, bytes_sent);
        return;
    }

    time_t now = time(NULL);
    char stamp[32];

    if (site == NULL)
        site = "-";

    strftime(stamp, sizeof(stamp),
             "%d/%b/%Y:%H:%M:%S %z", localtime(&now));

    if (content_length < 0)
        daemon_log(1, "%s %s - - [%s] \"%s %s HTTP/1.1\" %u %c\n",
                   site, request->remote_host, stamp,
                   http_method_to_string(request->method),
                   request->uri,
                   status,
                   content_length == -2 ? '-' : '?');
    else
        daemon_log(1, "%s %s - - [%s] \"%s %s HTTP/1.1\" %u %lu\n",
                   site, request->remote_host, stamp,
                   http_method_to_string(request->method),
                   request->uri,
                   status, (unsigned long)content_length);
}

#endif
<commit_msg>access-log: simplify Content-Length logging<commit_after>/*
 * Access logging.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "access-log.h"

#ifndef NO_ACCESS_LOG

#include "http-server.h"
#include "log-glue.h"

#include <time.h>

void
access_log(struct http_server_request *request, const char *site,
           http_status_t status, off_t content_length,
           uint64_t bytes_received, uint64_t bytes_sent)
{
    if (log_global_enabled()) {
        log_http_request(time(NULL) * 1000000, request->method, request->uri,
                         request->remote_host, site, NULL, NULL,
                         status, content_length,
                         bytes_received, bytes_sent);
        return;
    }

    time_t now = time(NULL);
    char stamp[32];

    if (site == NULL)
        site = "-";

    strftime(stamp, sizeof(stamp),
             "%d/%b/%Y:%H:%M:%S %z", localtime(&now));

    char length_buffer[32];
    const char *length;
    if (content_length == -2)
        length = "?";
    else if (content_length < 0)
        length = "-";
    else {
        snprintf(length_buffer, sizeof(length_buffer), "%llu",
                 (unsigned long long)content_length);
        length = length_buffer;
    }

    daemon_log(1, "%s %s - - [%s] \"%s %s HTTP/1.1\" %u %s\n",
               site, request->remote_host, stamp,
               http_method_to_string(request->method),
               request->uri,
               status, length);
}

#endif

{'fraction_non_alphanumeric': 0.14106476771787047, 'fraction_numerical': 0.013903017972193964, 'mean_word_length': 1.964824120603015, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '301111', 'n_tokens_mistral': 986, 'n_tokens_neox': 933, 'n_words': 202}