<commit_before>package com.github.benoitdion.ln;

import android.text.*;
import android.util.*;

public abstract class BaseLn implements NaturalLog {
    private static final ThreadLocal<String> TAG = new ThreadLocal<String>();
    private static final ThreadLocal<Ln.Context> CONTEXT = new ThreadLocal<Ln.Context>();
    private static final ThreadLocal<Integer> DEPTH = new ThreadLocal<Integer>();

    protected void println(int priority, boolean report, Throwable throwable, String message, Object... args) {
        message = args.length == 0 ? message : String.format(message, args);
        if (TextUtils.isEmpty(message)) {
            if (throwable != null) {
                message = formatThrowable(throwable);
            } else {
                // Nothing to log
                clearExtra();
                return;
            }
        } else if (throwable != null) {
            message += '\n' + formatThrowable(throwable);
        }
        if (report) {
            report(throwable, message);
        }

        Ln.Context context = CONTEXT.get();
        if (context != null) {
            CONTEXT.remove();
            String contextString = context.get();
            if (contextString != null) {
                Log.println(priority, getTag(), contextString + " " + formatMessage(message));
                return;
            }
        }
        Log.println(priority, getTag(), formatMessage(message));
    }

    protected String formatMessage(String message) {
        return message;
    }

    @Override
    public void report(Throwable throwable, String message) {
    }

    protected String formatThrowable(Throwable ex) {
        return Log.getStackTraceString(ex);
    }

    protected void clearExtra() {
        TAG.remove();
        CONTEXT.remove();
        DEPTH.remove();
    }

    public void tag(final String tag) {
        TAG.set(tag);
    }

    void extra(Ln.Context context, String tag, int depth) {
        CONTEXT.set(context);
        tag(tag);
        DEPTH.set(depth);
    }
<commit_msg>Add log extension point<commit_after>package com.github.benoitdion.ln;

import android.text.*;
import android.util.*;

public abstract class BaseLn implements NaturalLog {
    private static final ThreadLocal<String> TAG = new ThreadLocal<>();
    private static final ThreadLocal<Ln.Context> CONTEXT = new ThreadLocal<>();
    private static final ThreadLocal<Integer> DEPTH = new ThreadLocal<>();

    protected void println(int priority, boolean report, Throwable throwable, String message, Object... args) {
        message = args.length == 0 ? message : String.format(message, args);
        if (TextUtils.isEmpty(message)) {
            if (throwable != null) {
                message = formatThrowable(throwable);
            } else {
                // Nothing to log
                clearExtra();
                return;
            }
        } else if (throwable != null) {
            message += '\n' + formatThrowable(throwable);
        }
        if (report) {
            report(throwable, message);
        }

        Ln.Context context = CONTEXT.get();
        if (context != null) {
            CONTEXT.remove();
            String contextString = context.get();
            if (contextString != null) {
                log(priority, getTag(), contextString + " " + formatMessage(message));
                return;
            }
        }
        log(priority, getTag(), formatMessage(message));
    }

    protected String formatMessage(String message) {
        return message;
    }

    protected void log(int priority, String tag, String message) {
        Log.println(priority, tag, message);
    }

    @Override
    public void report(Throwable throwable, String message) {
    }

    protected String formatThrowable(Throwable ex) {
        return Log.getStackTraceString(ex);
    }

    protected void clearExtra() {
        TAG.remove();
        CONTEXT.remove();
        DEPTH.remove();
    }

    public void tag(final String tag) {
        TAG.set(tag);
    }

    void extra(Ln.Context context, String tag, int depth) {
        CONTEXT.set(context);
        tag(tag);
        DEPTH.set(depth);
    }

{'fraction_non_alphanumeric': 0.10991379310344827, 'fraction_numerical': 0.0004789272030651341, 'mean_word_length': 2.1032689450222883, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6267113', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1073, 'n_words': 288}