<commit_before>/*
 * Copyright (C) 2009 <NAME>, <NAME>
 * This software is licensed as described in the file COPYING in the root
 * directory of this distribution.
 *
 * Implements the logging subsystem for ObjectLite.
 */

#include "log.h"

#include "database.h"

#include <stdio.h>
#include <stdarg.h>
#include <time.h>

static const char *level_names[] = {
        "<default>", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "NONE"
};

static enum obl_log_level ambient_log_level = L_NOTICE;

#define TS_SIZE 24

void obl_set_ambient_log_level(enum obl_log_level level)
{
    ambient_log_level = level;
}

void obl_log(struct obl_database_config *config, enum obl_log_level level,
        const char *message)
{
    const char *filename;
    FILE *log_file;
    char timestamp[TS_SIZE];
    time_t timer;
    struct tm *local;

    if (config == NULL && ambient_log_level > level) {
        filename = NULL;
        return ;
    }

    if (config != NULL && config->log_level > level) {
        filename = config->filename;
        return ;
    }

    if (filename != NULL) {
        log_file = fopen(filename, "a+");
        if (log_file == NULL) {
            fprintf(stderr, "Unable to open the logging file <%s>.",
                    filename);
        }
    } else {
        log_file = stderr;
    }

    timer = time(NULL);<commit_msg>Correct a bug with the logging stuff i just changed.<commit_after>/*
 * Copyright (C) 2009 <NAME>, <NAME>
 * This software is licensed as described in the file COPYING in the root
 * directory of this distribution.
 *
 * Implements the logging subsystem for ObjectLite.
 */

#include "log.h"

#include "database.h"

#include <stdio.h>
#include <stdarg.h>
#include <time.h>

static const char *level_names[] = {
        "<default>", "DEBUG", "INFO", "NOTICE", "WARN", "ERROR", "NONE"
};

static enum obl_log_level ambient_log_level = L_NOTICE;

#define TS_SIZE 24

void obl_set_ambient_log_level(enum obl_log_level level)
{
    ambient_log_level = level;
}

void obl_log(struct obl_database_config *config, enum obl_log_level level,
        const char *message)
{
    const char *filename;
    FILE *log_file;
    char timestamp[TS_SIZE];
    time_t timer;
    struct tm *local;

    if (config == NULL) {
        if (ambient_log_level > level)
            return ;
        filename = NULL;
    } else {
        if (config->log_level > level)
            return ;
        filename = config->filename;
    }

    if (filename != NULL) {
        log_file = fopen(filename, "a+");
        if (log_file == NULL) {
            fprintf(stderr, "Unable to open the logging file <%s>.",
                    filename);
        }
    } else {
        log_file = stderr;
    }

    timer = time(NULL);
{'fraction_non_alphanumeric': 0.11827169534968876, 'fraction_numerical': 0.004393994873672647, 'mean_word_length': 2.6475300400534048, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '552714', 'n_tokens_mistral': 905, 'n_tokens_neox': 881, 'n_words': 258}