<commit_before>﻿using System;

namespace Discore
{
    public class DiscoreLogEventArgs : EventArgs
    {
        public readonly DiscoreLogLine Line;

        internal DiscoreLogEventArgs(DiscoreLogLine line)
        {
            Line = line;
        }
    }

    /// <summary>
    /// Represents a single logged line.
    /// </summary>
    public class DiscoreLogLine
    {
        /// <summary>
        /// The contents of this line.
        /// </summary>
        public readonly string Message;
        /// <summary>
        /// The type of line.
        /// </summary>
        public readonly DiscoreLogType Type;
        /// <summary>
        /// The date/time the line was logged.
        /// </summary>
        public readonly DateTime Timestamp;

        internal DiscoreLogLine(string msg, DiscoreLogType type, DateTime timestamp)
        {
            Message = msg;
            Type = type;
            Timestamp = timestamp;
        }
    }

    /// <summary>
    /// The type of a <see cref="DiscoreLogLine"/>.
    /// </summary>
    public enum DiscoreLogType
    {
        Verbose,
        Info,
        Warning,
        Error
    }

    /// <summary>
    /// A logger for Discore related systems.
    /// </summary>
    public class DiscoreLogger
    {
        /// <summary>
        /// Called when a line is logged from any <see cref="DiscoreLogger"/>.
        /// </summary>
        public static event EventHandler<DiscoreLogEventArgs> OnLog;

        /// <summary>
        /// Gets the default <see cref="DiscoreLogger"/>.
        /// </summary>
        public static DiscoreLogger Default { get; }

        /// <summary>
        /// Gets or sets the prefix for this <see cref="DiscoreLogger"/>.
        /// </summary>
        public string Prefix { get; set; }

        static DiscoreLogger()
        {
            Default = new DiscoreLogger("");
        }

        /// <summary>
        /// Creates a new <see cref="DiscoreLogger"/> instance.
        /// </summary>
        /// <param name="prefix">The prefix of this logger.</param>
        public DiscoreLogger(string prefix)
        {
            Prefix = prefix;
        }

        /// <summary>
        /// Logs a line to this logger.
        /// </summary>
        /// <param name="msg">The contents of this log.</param>
        /// <param name="type">The type of log.</param>
        public void Log(string msg, DiscoreLogType type)
        {
            if (!string.IsNullOrWhiteSpace(Prefix))
                // Prefix
                msg = $"[{Prefix}] {msg}";

            try { OnLog?.Invoke(this, new DiscoreLogEventArgs(new DiscoreLogLine(msg, type, DateTime.Now))); }
            // Log methods need to be guaranteed to never throw exceptions.
            catch { }
        }

        /// <summary>
        /// Logs a verbose message.
        /// </summary>
        /// <param name="msg">The contents of this log.</param>
        public void LogVerbose(string msg)
        {
            Log(msg, DiscoreLogType.Verbose);
        }

        /// <summary>
        /// Logs an info message.
        /// </summary><commit_msg>Add DiscoreLogger.MinimumLevel<commit_after>﻿using System;

namespace Discore
{
    public class DiscoreLogEventArgs : EventArgs
    {
        public readonly DiscoreLogLine Line;

        internal DiscoreLogEventArgs(DiscoreLogLine line)
        {
            Line = line;
        }
    }

    /// <summary>
    /// Represents a single logged line.
    /// </summary>
    public class DiscoreLogLine
    {
        /// <summary>
        /// The contents of this line.
        /// </summary>
        public readonly string Message;
        /// <summary>
        /// The type of line.
        /// </summary>
        public readonly DiscoreLogType Type;
        /// <summary>
        /// The date/time the line was logged.
        /// </summary>
        public readonly DateTime Timestamp;

        internal DiscoreLogLine(string msg, DiscoreLogType type, DateTime timestamp)
        {
            Message = msg;
            Type = type;
            Timestamp = timestamp;
        }
    }

    /// <summary>
    /// The type of a <see cref="DiscoreLogLine"/>.
    /// </summary>
    public enum DiscoreLogType
    {
        Verbose,
        Info,
        Warning,
        Error
    }

    /// <summary>
    /// A logger for Discore related systems.
    /// </summary>
    public class DiscoreLogger
    {
        /// <summary>
        /// Called when a line is logged from any <see cref="DiscoreLogger"/>.
        /// </summary>
        public static event EventHandler<DiscoreLogEventArgs> OnLog;

        /// <summary>
        /// Gets the default <see cref="DiscoreLogger"/>.
        /// </summary>
        public static DiscoreLogger Default { get; }

        /// <summary>
        /// Gets or sets the minimum log level to be sent through the <see cref="OnLog"/> event.
        /// <para>
        /// For example: A log level of <see cref="DiscoreLogType.Info"/> will log 
        /// everything except <see cref="DiscoreLogType.Verbose"/>.
        /// </para>
        /// <para>
        /// This defaults to <see cref="DiscoreLogType.Verbose"/> when compiled with the DEBUG preprocessor,
        /// otherwise defaults to <see cref="DiscoreLogType.Info"/>.
        /// </para>
        /// </summary>
        public static DiscoreLogType MinimumLevel { get; set; }

        /// <summary>
        /// Gets or sets the prefix for this <see cref="DiscoreLogger"/>.
        /// </summary>
        public string Prefix { get; set; }

        static DiscoreLogger()
        {
            Default = new DiscoreLogger("");

#if DEBUG
            MinimumLevel = DiscoreLogType.Verbose;
#else
            MinimumLevel = DiscoreLogType.Info;
#endif
        }

        /// <summary>
        /// Creates a new <see cref="DiscoreLogger"/> instance.
        /// </summary>
        /// <param name="prefix">The prefix of this logger.</param>
        public DiscoreLogger(string prefix)
        {
            Prefix = prefix;
        }

        /// <summary>
        /// Logs a line to this logger.
        /// </summary>
        /// <param name="msg">The contents of this log.</param>
        /// <param name="type">The type of log.</param>
        public void Log(string msg, DiscoreLogType type)
        {
            if (type >= MinimumLevel)
            {
                if (!string.IsNullOrWhiteSpace(Prefix))
                    // Prefix
                    msg = $"[{Prefix}] {msg}";

                try { OnLog?.Invoke(this, new DiscoreLogEventArgs(new DiscoreLogLine(msg, type, DateTime.Now))); }
                // Log methods need to be guaranteed to never throw exceptions.
                catch { }
            }
        }

        /// <summary>
        /// Logs a verbose message.
        /// </summary>
        /// <param name="msg">The contents of this log.</param>
        public void LogVerbose(string msg)
        {
            Log(msg, DiscoreLogType.Verbose);
        }

        /// <summary>
        /// Logs an info message.
        /// </summary>
{'fraction_non_alphanumeric': 0.12597200622083982, 'fraction_numerical': 0.0, 'mean_word_length': 1.4873417721518987, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 95, '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': '3923670', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1834, 'n_words': 550}