<commit_before>package com.codingchili.core.logging;

import com.codingchili.core.configuration.Environment;
import com.codingchili.core.context.CoreContext;
import com.codingchili.core.context.Delay;
import com.codingchili.core.listener.CoreListener;
import com.codingchili.core.listener.CoreService;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import static com.codingchili.core.configuration.CoreStrings.*;
import static com.codingchili.core.files.Configurations.launcher;

/**
 * @author <NAME>
 * <p>
 * Default logging implementation.
 */
public abstract class DefaultLogger extends Handler implements Logger {
    protected Map<String, Supplier<String>> metadata = new HashMap<>();
    protected CoreContext context;
    protected JsonLogger logger;
    protected Class aClass;
    private Level level = Level.INFO;

    public DefaultLogger(CoreContext context, Class aClass) {
        this.context = context;
        this.aClass = aClass;
    }

    public DefaultLogger(Class aClass) {
        this.aClass = aClass;
    }

    @Override
    public Logger log(JsonObject json) {
        logger.log(json
                .put(PROTOCOL_ROUTE, PROTOCOL_LOGGING)
                .put(LOG_TIME, Instant.now().toEpochMilli()));
        return this;
    }

    @Override
    public Logger setMetadata(String key, Supplier<String> value) {
        metadata.put(key, value);
        return this;
    }

    private JsonObject event(String name) {
        return event(name, Level.INFO);
    }

    @Override
    public JsonObject event(String name, Level level) {
        JsonObject event = new JsonObject()
                .put(PROTOCOL_ROUTE, PROTOCOL_LOGGING)
                .put(LOG_EVENT, name)
                .put(LOG_LEVEL, level)
                .put(LOG_TIME, Instant.now().toEpochMilli());
        addMetadata(event);
        return event;
    }

    /**
     * Adds metadata to logging events generated by the logger.
     *
     * @param event the log event to add metadata to.
     */
    protected void addMetadata(JsonObject event) {
        if (context != null) {
            event.put(LOG_HOST, Environment.hostname().orElse(ID_UNDEFINED))
                    .put(LOG_SOURCE, aClass.getName())
                    .put(LOG_APPLICATION, launcher().getApplication());
        }
        metadata.forEach((key, value) -> event.put(key, value.get()));
    }<commit_msg>Use simple class names when logging.<commit_after>package com.codingchili.core.logging;

import com.codingchili.core.configuration.Environment;
import com.codingchili.core.context.CoreContext;
import com.codingchili.core.context.Delay;
import com.codingchili.core.listener.CoreListener;
import com.codingchili.core.listener.CoreService;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import static com.codingchili.core.configuration.CoreStrings.*;
import static com.codingchili.core.files.Configurations.launcher;

/**
 * @author <NAME>
 * <p>
 * Default logging implementation.
 */
public abstract class DefaultLogger extends Handler implements Logger {
    protected Map<String, Supplier<String>> metadata = new HashMap<>();
    protected CoreContext context;
    protected JsonLogger logger;
    protected Class aClass;
    private Level level = Level.INFO;

    public DefaultLogger(CoreContext context, Class aClass) {
        this.context = context;
        this.aClass = aClass;
    }

    public DefaultLogger(Class aClass) {
        this.aClass = aClass;
    }

    @Override
    public Logger log(JsonObject json) {
        logger.log(json
                .put(PROTOCOL_ROUTE, PROTOCOL_LOGGING)
                .put(LOG_TIME, Instant.now().toEpochMilli()));
        return this;
    }

    @Override
    public Logger setMetadata(String key, Supplier<String> value) {
        metadata.put(key, value);
        return this;
    }

    private JsonObject event(String name) {
        return event(name, Level.INFO);
    }

    @Override
    public JsonObject event(String name, Level level) {
        JsonObject event = new JsonObject()
                .put(PROTOCOL_ROUTE, PROTOCOL_LOGGING)
                .put(LOG_EVENT, name)
                .put(LOG_LEVEL, level)
                .put(LOG_TIME, Instant.now().toEpochMilli());
        addMetadata(event);
        return event;
    }

    /**
     * Adds metadata to logging events generated by the logger.
     *
     * @param event the log event to add metadata to.
     */
    protected void addMetadata(JsonObject event) {
        if (context != null) {
            event.put(LOG_HOST, Environment.hostname().orElse(ID_UNDEFINED))
                    .put(LOG_SOURCE, aClass.getSimpleName())
                    .put(LOG_APPLICATION, launcher().getApplication());
        }
        metadata.forEach((key, value) -> event.put(key, value.get()));
    }
{'fraction_non_alphanumeric': 0.10470701248799232, 'fraction_numerical': 0.0, 'mean_word_length': 2.813919413919414, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '3314311', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1478, 'n_words': 341}